Why am I getting an error with this form choice set to multiple. This is coming directly off of Symfonys website. All I changed was the variable name.
$builder->add('genre', 'choice', array(
'choices' => array(
'x' => 'x',
'y' => 'y',
'z' => 'z',
),
'multiple' => true,
));
This is the error:
Unable to transform value for property path "genre": Expected an array.
Here is my entity class for this variable:
/**
* @var string
*
* @ORM\Column(name="genre", type="text", nullable=true)
*/
private $genre;
I can confirm that the comment by qooplmao solves the issue:
The problem is that your entity field $genre
is not defied as an array
but as a string
.
But when multiple choices are enabled, the form field will provide an array
as a result, and not a string.
So you can:
genre
as an array
instead of a string
multiple
to falseI this specific problem I guess that you want to map genre
as an array
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With