Symfony2表单集合:显示当前对象的索引 [英] Symfony2 form collection: Index of the current object is shown
本文介绍了Symfony2表单集合:显示当前对象的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当显示我的实体集合时,我有这样的事情:
0
名称:myInputName
地址:myInputAddress
1
名称:myInputName
地址:myInputAddress
我的问题是为什么Symfony2显示索引 ...
对于所有已保存的实体,我将其添加到我的集合中...
这里我使用的代码:
$ builder
- > add('person','collection',array(
'label'=>'',
'type'=> new PersonType(),
'prototype'=> true,
'allow_add'=> true,
'allow_delete'=> true,
'by_reference'=> false,
))
;
在我的twig文件中:
< DIV>
{{form_widget(edit_form)}}
< / div>
请帮助
Sam
解决方案
您可以自定义集合的渲染,以便不显示索引,例如:
{%block _FORMNAME_person_widget%}
{%spaceless%}
{%for form in%}
{{form_widget (child.Name)}}
{{form_widget(child.Address)}}
{%endfor%}
{%endpacepaceless%}
{%endblock%}
I've got a problem with displaying collection in my form.
When displaying my entity collection I've got something like this :
0
Name: myInputName
Address: myInputAddress
1
Name: myInputName
Address: myInputAddress
My question is why Symfony2 display the index...
And this for all saved entities into my collection...
Here the code I use:
$builder
->add('person', 'collection', array(
'label' => ' ',
'type' => new PersonType(),
'prototype' => true,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
))
;
In my twig file:
<div>
{{ form_widget(edit_form) }}
</div>
Help please
Sam
解决方案
You can custom the rendering of your collection for don't display the index with, by example:
{% block _FORMNAME_person_widget %}
{% spaceless %}
{% for child in form %}
{{ form_widget(child.Name) }}
{{ form_widget(child.Address) }}
{% endfor %}
{% endspaceless %}
{% endblock %}
这篇关于Symfony2表单集合:显示当前对象的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文