1

我正在尝试实现一个可以接受表单数组的 form_function。

FormExtension 看起来像这样:

[...]
'form_controls_row'  => new \Twig_Function_Node('Symfony\Bridge\Twig\Node\RenderBlockNode', array('is_safe' => array('html'))),
[...]

我的 field.html.twig 是这样的:

{% extends 'MopaBootstrapBundle:Form:fields.html.twig' %}

{# import "_self" as the form theme #}
{% form_theme form _self %}

{# make the form fragment customization #}
{% block form_controls_row %}
    {% spaceless %}
        <div class="controls controls-row">
            {% for element in form %}
                {{ form_row(element, _context) }}
            {% endfor %}
        <div>
    {% endspaceless %}
{% endblock form_controls_row %}

我的表单本身看起来像这样:

    {% form_theme form 'MyBundle::fields.html.twig' %}

<div class="well">
    <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
        {{ form_controls_row([form.firstName, form.lastName]) }}
        {{ form_rest(form) }}
    </form>
</div>

但是每次我将一个数组([form.firstName,form.lastName])传入 form_controls_row 时,都会出现异常。有没有办法允许数组?

或者有没有更好的解决方案适合我的目的?

4

0 回答 0