CakePHP 3.7.1 添加 类 到表单 Select 控件选项
CakePHP 3.7.1 Add Classes to Form Select Control Options
根据文档,我已经能够构建一个表单 Select 控件,但是,我不清楚如何将 类 添加到 select 选项...
这是我在 CakePHP 表单中的 select 控件
<?= $this->Form->select('type', [
'Value 1' => 'Name 1',
'Value 2' => 'Name 2'
],[
'class' => 'js-custom-select w-100 u-select-v2 u-shadow-v19 g-brd-none g-color-black g-color-primary--hover g-bg-white text-left g-rounded-30 g-pl-30 g-py-12',
'data-open-icon' => "fa fa-angle-down",
'data-close-icon' => "fa fa-angle-up"
]
) ?>
这是我在 HTML
中的 select 控件
<select name="type" class="js-custom-select w-100 u-select-v2 u-shadow-v19 g-brd-none g-color-black g-color-primary--hover g-bg-white text-left g-rounded-30 g-pl-30 g-py-12" data-placeholder="Type" data-open-icon="fa fa-angle-down" data-close-icon="fa fa-angle-up">
<option class="g-brd-secondary-light-v2 g-color-black g-color-white--active g-bg-primary--active" value="value 1">Name 1</option>
<option class="g-brd-secondary-light-v2 g-color-black g-color-white--active g-bg-primary--active" value="value 2">Name 2</option>
</select>
如何将选项上的 类 放入控件的 CakePHP 表单中?
要将 类 添加到您的选项中,您需要使用特定的选项数组结构:
$options = [
[
"text" => "Text to display for option 1",
"value" => "Value to set for option 1",
"class" => "Class list to set for option 1"
],
[
"text" => "Text to display for option 2",
"value" => "Value to set for option 2",
"class" => "Class list to set for option 2"
],
/** ... **/
]
准备好这样的数组后,你可以用FormHelper::select()
或FormHelper::control()
:
$this->Form->select("field_name",$options);
$this->Form->control("field_name",[
"label" => "My Label",
"type" => "select",
"options" => $options
]);
根据文档,我已经能够构建一个表单 Select 控件,但是,我不清楚如何将 类 添加到 select 选项...
这是我在 CakePHP 表单中的 select 控件
<?= $this->Form->select('type', [
'Value 1' => 'Name 1',
'Value 2' => 'Name 2'
],[
'class' => 'js-custom-select w-100 u-select-v2 u-shadow-v19 g-brd-none g-color-black g-color-primary--hover g-bg-white text-left g-rounded-30 g-pl-30 g-py-12',
'data-open-icon' => "fa fa-angle-down",
'data-close-icon' => "fa fa-angle-up"
]
) ?>
这是我在 HTML
中的 select 控件<select name="type" class="js-custom-select w-100 u-select-v2 u-shadow-v19 g-brd-none g-color-black g-color-primary--hover g-bg-white text-left g-rounded-30 g-pl-30 g-py-12" data-placeholder="Type" data-open-icon="fa fa-angle-down" data-close-icon="fa fa-angle-up">
<option class="g-brd-secondary-light-v2 g-color-black g-color-white--active g-bg-primary--active" value="value 1">Name 1</option>
<option class="g-brd-secondary-light-v2 g-color-black g-color-white--active g-bg-primary--active" value="value 2">Name 2</option>
</select>
如何将选项上的 类 放入控件的 CakePHP 表单中?
要将 类 添加到您的选项中,您需要使用特定的选项数组结构:
$options = [
[
"text" => "Text to display for option 1",
"value" => "Value to set for option 1",
"class" => "Class list to set for option 1"
],
[
"text" => "Text to display for option 2",
"value" => "Value to set for option 2",
"class" => "Class list to set for option 2"
],
/** ... **/
]
准备好这样的数组后,你可以用FormHelper::select()
或FormHelper::control()
:
$this->Form->select("field_name",$options);
$this->Form->control("field_name",[
"label" => "My Label",
"type" => "select",
"options" => $options
]);