Answer the question
In order to leave comments, you need to log in
How to create Choice in Entity in symfony 3?
Good
afternoon I'm torturing Symfony, but she's me
The essence of the problem: you need to create a form with a choice (select) of 2 options
Question: is it possible to specify all valid 2 options in Entity ?
Before that, I worked with Django - and there selection options could be made right when declaring a field ...
Something tells me that in symphony you can do the same ...
Now in Entity like this:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @var int
*
* @Assert\Choice( choices = {1:"male", 2:"female"}, message = "Choose a valid priority.")
*/
protected $priority;
Answer the question
In order to leave comments, you need to log in
The Assert annotation refers to the validation component. It has nothing to do with the doctrine and work with the base.
See the enum annotation for doctrine. symfony has great documentation. I'd deploy the symfony-demo for reference and a basic understanding.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question