CakePHP 表单助手 - HABTM 多复选框样式
我有两张表:“餐厅”和“菜品”,它们通过 HABTM 表相互关联。
表菜品有某些固定条目 - 54 个数字
一家餐厅可以有任意数量的菜品。在烘焙应用程序时,它带有多个选择。因为我想要复选框,所以我使用 array( 'type' => 'select', 'multiple' => 'checkbox') 将其转换为复选框。
现在我想设置此复选框显示为 4 列的样式,如下面的屏幕截图所示。
img2.pict。 com/82/bc/a4/1453459/0/200908111511.png
echo $form->input('Cuisine', array('type' => 'select', 'multiple' => 'checkbox'));
上面的代码在每个元素周围生成许多 div,如下
http://img2.pict.com/1a/a3/0a/1453457/0/200908121509.png
我已尝试以下操作:
echo $form->input('Cuisine', array( 'type' => 'select', 'multiple' => 'checkbox', 'div' => false, 'label' => false));
但此代码仅删除外部 div 和标签。我无法控制
<div class="checkbox">
<label for="CuisineCuisine2">Andhra</label>
单个复选框周围出现的内部。
如何使用 FormHelper 删除内部 div 或为其提供类,以便我可以执行一些自定义样式? 或者有没有其他方法来填充这个 HABTM 表以获得我想要的效果?
I have two tables: "restaurants" and "cuisines" which are related to each other by a HABTM table
The table cuisines has certain fixed entries - 54 number
A restaurant can have any number of cuisines. On baking the application this came with a multiple select. Since i wanted check boxes i used array( 'type' => 'select', 'multiple' => 'checkbox') to convert it into checkboxes.
Now i want to style the way this checkboxes are displayed into columns of 4 as seen on the screenshot below.
img2.pict. com/82/bc/a4/1453459/0/200908111511.png
echo $form->input('Cuisine', array('type' => 'select', 'multiple' => 'checkbox'));
The above code produces many div's around each element as follows
http://img2.pict.com/1a/a3/0a/1453457/0/200908121509.png
I have tried the following:
echo $form->input('Cuisine', array( 'type' => 'select', 'multiple' => 'checkbox', 'div' => false, 'label' => false));
but this code only removes the outside divs and label. I am not able to control the internal
<div class="checkbox">
<label for="CuisineCuisine2">Andhra</label>
that appear around the single checkboxes.
How can I use the FormHelper to remove or give classes to the internal divs, so I can do some custom styling?
Or is there any other way to populate this HABTM table to get the effect i want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过执行 $form->select() 来解决此问题,并应用样式或类属性以使其看起来像您想要的那样。
如果您无论如何都要删除 div 和标签,那么不使用 $form->input() 函数似乎是有意义的。
You could get around this by doing $form->select() instead, and apply a style or class attribute to get it to look how you want.
It seems to make sense to not use the $form->input() function if you are going to remove the div and label anyway.
您可以使用 CSS 来设计 DIV 元素的样式。
You can stylize the DIV elements with CSS.
您可以像这样删除或给内部 div 提供类
默认 cake 使用: type class 例如 - 类型是 checkbox 然后
class="checkbox"
You can remove or give classes to the internal divs like this
By default cake uses : type class e.g - type is checkbox then
class="checkbox"