簡體   English   中英

如何在symfony2的自定義表單字段中獲取表單變量

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM