如何访问twig中集合中的字段
$builder
->add('name', 'text', array('required' => false))
->add('email', 'collection', array(
'type' => new UsersEmailAddressesType(),
'allow_add' => true
))UserEmailAddressesType有两个字段name和email,如何在twig中访问电子邮件字段?
发布于 2013-05-28 21:56:23
在symfony的食谱中有一个关于how to embed collections in forms的例子。这里的解决方案如下所示(适用于您的表单示例):
<ul>
{% for email in form.email %}
<li>{{ form_row(email.address) }}</li>
{% endfor %}
</ul>由于您希望将输入放在一起,因此可能需要检查loop.index是odd、even还是divisibleby(),例如:
{% for email in form.email %}
{% if loop.index is odd %}
<li class="float-left">
{% else %}
<li class="float-right">
{% endif %}
{{ form_row(email.address) }}</li>
{% endfor %}https://stackoverflow.com/questions/16793543
复制相似问题