I have a simple question about Symfony2's form type "collection" in combination with doctrine's column "array".**
My Entity:
/**
* @Column(type="array", nullable=true)
* @var array
*/
private $specifications;
My "Main" Form:
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('specifications', 'collection', array (
'type' => new ProductSpecificationType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false
)
);
}
My "ProductSpecificationsType" Form:
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('group', 'text')
->add('info', 'text')
;
}
And my output with button (twig):
{{ form_row(form.specifications) }}
<a data-prototype="{{ form_widget(form.specifications.vars.prototype) | e }}" href="#" onclick="return false;">Add</a>
The real outout is this (html):
<a data-prototype="" href="#" onclick="return false;">Add</a>
And the same if I use only the form_widget without the "e" like "escape" at the end.
After save the entity is saved with the array column = null.
So, if I add these lines per FireBug manually to the html form
<input type="text" name="product[specifications][0][group]" value="Exam">
<input type="text" name="product[specifications][0][info]" value="ple">
<input type="text" name="product[specifications][1][group]" value="Extra">
<input type="text" name="product[specifications][1][info]" value="Example">
and press then "Save", the entity is saved in this format:
a:2:{i:0;a:2:{s:5:"group";s:4:"Exam";s:4:"info";s:3:"ple";}i:1;a:2:{s:5:"group";s:5:"Extra";s:4:"info";s:7:"Example";}}
My questions:
Why is my prototype empty?
Why is the form_widget empty? (is also empty if I fill the data above manually!)
Thank you in advance!