Reputation: 3216
I have symfony form with field
->add('roles', ChoiceType::class, [
'choices' => [
'Developer' => 'ROLE_DEVELOPER',
'Support' => 'ROLE_SUPPORT',
'Admin' => 'ROLE_ADMIN'
],
'multiple' => true,
]);
And I want to remove multiple option, but symfony fall down with exception
phpfpm_1 | NOTICE: PHP message: [critical] Uncaught PHP Exception ErrorException: "Notice: Array to string conversion" at /var/www/symfony/vendor/symfony/form/ChoiceList/ArrayChoiceList.php line 68
How to avoid it?
Upvotes: 1
Views: 209
Reputation: 173
in the database the roles field is defined as array so the choice type must return a value of type array. to resolve this issue u should use Data Transformers (convert array to string). check this: https://symfony.com/doc/current/form/data_transformers.html
Upvotes: 2