CakePHP 表单助手 - HABTM 多复选框样式

发布于 2024-08-02 11:42:44 字数 1039 浏览 6 评论 0原文

我有两张表:“餐厅”和“菜品”,它们通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧人哭 2024-08-09 11:42:44

您可以通过执行 $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.

行至春深 2024-08-09 11:42:44

您可以使用 CSS 来设计 DIV 元素的样式。

<style>
div.input div.checkbox {
    float: left;
    width: 50%;
}
</style>

You can stylize the DIV elements with CSS.

<style>
div.input div.checkbox {
    float: left;
    width: 50%;
}
</style>
寄与心 2024-08-09 11:42:44

您可以像这样删除或给内部 div 提供类

$this->Form->input("hello_test",array('type'=>'checkbox','div'=>'class_name'));

默认 cake 使用: type class 例如 - 类型是 checkbox 然后 class="checkbox"

You can remove or give classes to the internal divs like this

$this->Form->input("hello_test",array('type'=>'checkbox','div'=>'class_name'));

By default cake uses : type class e.g - type is checkbox then class="checkbox"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文