1

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?

1
  • Please share more details. This works as long as multiple => true is given, but after removing that line, it fails? Commented Oct 23, 2020 at 10:14

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.