html - CakePHP 3.7.1 向表单选择控件选项添加类
问题描述
从文档中,我已经能够构建一个表单选择控件,但是,我不清楚如何将类添加到选择选项中......
这是我在 CakePHP 表单中的选择控件
<?= $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 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()
or一起使用FormHelper::control()
:
$this->Form->select("field_name",$options);
$this->Form->control("field_name",[
"label" => "My Label",
"type" => "select",
"options" => $options
]);
推荐阅读
- aws-lambda - 从 lambda 函数代码中识别触发器或查找 dynamodb 表名
- python - 使用 PyTorch DataLoader 让我有同样的损失,循环没有任何进展
- python - 如何用python制作一个类似鼠标定位器的程序?(如定位鼠标光标位置的免费实用程序)
- spring - 如何使用 JWT spring boot 处理多设备身份验证
- php - 带有函数参数的异常类
- amazon-ec2 - 从网站访问地理服务器(托管在 EC2 上)
- python - 具有任务管理队列的 Python 微服务
- javascript - 椭圆曲线 JavaScript 库中的错误:没有 r 或 s 的签名?
- java - 如何在 Firebase 中按日期时间订购适配器
- javascript - 在 react-table 的单元格中将字符串呈现为 html