[英]How to get form variables in custom form field in symfony2
我有这个自定义表单字段
{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
{% block gender_widget %}
{% spaceless %}
{% if expanded %}
<ul {{ block('widget_container_attributes') }}>
{% for child in form %}
<li>
{{ form_widget(child) }}
{{ form_label(child) }}
</li>
{% endfor %}
</ul>
{% else %}
{# just let the choice widget render the select tag #}
{{ block('choice_widget') }}
{% endif %}
{% endspaceless %}
{% endblock %}
这将呈现复选框。 但是我找不到如何获取复选框的值
即child.form.value
不起作用。
假设我有在表单中被称为任务的实体。
我如何获得TaskID的值。
就像是
child.form.vars.task.id
它似乎在{{ choice.value }}
看看这个 ,看看继承是如何工作的。
<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.