2012-08-25 42 views
1

我有這樣的自定義表單字段自定義表單字段如何獲得表單變量在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

回答

1

這似乎是在{{ choice.value }}

看一看this看到的繼承是如何工作的。

<option value="{{ choice.value }}"{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ choice.label|trans({}, translation_domain) }}</option> 
相關問題