I have an extension to this question: How do I work with a collection of forms in Symfony2 beta? - My project is similar, but the objects are nested deeper. I have articles containing one or more content elements, each of which contains one or more media. While the model and the controllers are working fine, but I do not know how to properly represent the nesting in my template. The form /ContentType.php looks right:
class ContentType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('headline') ->add('text') ->add('medias', 'collection', array( 'type' => new MediaType(), 'allow_add' => true )) ; }
And until now, the form template for creating (or editing) an article looks like this (almost a vanilla auto-generated template):
... <form action="{{ path('article_create') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} {% for content in form.contents %} {{ form_widget(content) }} {% endfor %} <p> <button type="submit">Create</button> </p> </form> ...
How can I access each Media Media content so that it is correctly associated?
Fester bestertester
source share