gpt4 book ai didi

symfony - symfony 2 表单中的复选框

转载 作者:行者123 更新时间:2023-12-01 05:23:31 25 4
gpt4 key购买 nike

我在 Controller 中定义了一个表单,如下所示:

$addForm = $this->createFormBuilder()
->add('userIds', 'collection', array(
'type' => 'checkbox',
'allow_add' => true,
'options' => array(
'required' => false
)
))
->add('userId', 'hidden')
->getForm();

在 View 中,我正在显示一个带有批量删除选项的数据网格。我正在使用 knp paginator 进行分页。我在 View 中手动渲染字段,如下所示:
//Inside loop
{%for items in pagination %}
<input type="checkbox" name="form[userIds][]" class="ids" value="{{items.id}}"/>
{%endfor%}

我在发布请求后在 Controller 中获取数据,如下所示:
 var_dump($data['userIds']); 

当用户选择假设三个复选框时,我得到如下输出:
array (size=4)
0 => boolean true
1 => boolean true
2 => boolean true
3 => boolean true

这些值应该包含像 1,5,6,7 这样的用户 ID,但我只得到 bool 值。我做错了什么?

最佳答案

考虑使用 Entity field type : 调整 expandedmultiple属性,您将获得一个复选框列表,这些复选框将在提交时绑定(bind)到您的模型模式。

关于symfony - symfony 2 表单中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15185167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com