0
votes

i have an array with entities. I know that symfony has a collection type, but that what i want doesn't work as intended. I have created a FormType for a single entity and a FormType for the collection (formtype code for the collection):

$builder
            ->add('list', 'collection', array(
                'label' => 'list',
                'type' => new SingleItemType(),
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false
            ));

Now i have tried to create a Form

$arr = array(new Item(), new Item(), new Item());
$this->createForm(new CollectionListType(), $arr);

But this doesn't work; I get an error which means i should set "Item" as data_class, if i do this, an another error appears which means i should set data_class to null.

Another approach was to create a dummy entity which holds my array of Item-Entities but this doesn't works too.

Is there a simple approach to display a list of entities as collection form?

Greetings

1
Have you tried this cookbook entry, how to embed a collection of forms? - Veve

1 Answers

0
votes

I'm not sure totally understand your problem but I think you must create first an Entity with getList()/setList(). In your collection field, you can add a new "default" entity passing a value to "data" key in option array.