gpt4 book ai didi

forms - Symfony2 表格 : Generating checkboxes

转载 作者:行者123 更新时间:2023-12-04 09:41:54 24 4
gpt4 key购买 nike

目前我有一个表单,它从我的类别实体中生成一个下拉选择:

        $builder
->add('category', 'entity',
array('class' => 'TrackerMembersBundle:Category',
'property' => 'title',));

现在我想改为生成复选框,我可以在其中选择多个选项...我搜索了 symfony2 文档,但找不到直接从我的实体中执行此操作的简单方法。有什么想法吗?

最佳答案

'multiple' => true 添加到选项数组(class 和 property 所在的最后一个)给你一个多选。

然后您可以使用 form theming 覆盖 choice_widget block .

这样的事情可能会起作用:

{% block choice_widget %}
{% spaceless %}
{% for choice, label in choices %}
<label>
<input type="checkbox" value="{{ choice }}"{% if _form_is_choice_selected(form, choice) %} selected="selected"{% endif %}>
{{ label|trans }}
</label>
{% endfor %}
{% endspaceless %}
{% endblock choice_widget %}

关于forms - Symfony2 表格 : Generating checkboxes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9466293/

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