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
Using @MrBandersnatch's solution below, I had to use
$view->vars['name']
instead of$this->vars['name']
(Symfony 2.3).(apologies for not adding this as a comment on @MrBandersnatch's answer, I've not got enough reputation yet).
You can custom the rendering of your collection for don't display the index with, by example:
Removing indexes (labels) for collection items:
If you want to add custom labels per row you can produce the form yourself:
Note: tested on Symfony 2.3 & 2.4
I know this has been closed for a while. And not sure if this has been solved elsewhere. This issue is actually pretty simple to fix and I am surprised there is no documentation about this anywhere. In the PersonType or any type that is used in a collections just modify the vars['name'] in the buildView to be what you want displayed as the label.
If you want it dynamic, you would use the object by form->getData(). Since, in my problem, I am using a form theme, overriding the twig is not really an option for me.
Hope this helps someone.
This one is some days ago but because I was facing same question for Symfony 3 the answer of sectus is the correct one.
Use the
option within your builder to hide he object item.
Best Regards