Reputation: 227
In Symfony 2.3 i am using SonataAdminBundle. In my Entity i have the following field:
/**
* @var array
* @ORM\Column(name="testimonial", type="array" )
*/
protected $testimonials;
in my Admin class when i try to render the form or listing with
->add('testimonials')
there will be no input in the form and in listing it causes an array to string exception.
in a row i am saving a testimonial like
array(
'title' => 'test'
'author' => 'test'
);
So what would be the best way to get it working? For my form i only need a simple text field in with i can fill in my array. Also the whole array should be shown in show/ listing.
Thank you
Upvotes: 2
Views: 2138
Reputation: 10084
You should use Data Transformers. In this case you will be able to manage how to render array type and how to persist form data for this type in the database.
And finally your SonataAdmin form mapper will be look ike this:
->add($formMapper->create('testimonials', 'fieldType')
->addViewTransformer($someTransformer)
)
Upvotes: 3