I have a class like this:
class Student {
const GENDER_MALE = "male", GENDER_FEMALE = "female";
/**
* @var string $gender
*
* @ORM\Column(name="gender", type="string", length=50,nullable=false)
* @Assert\NotBlank(message="Gender cannot be blank",groups={"new"})
* @Assert\Choice(choices = {"male", "female"}, message = "Choose a valid gender.", groups={"new"})
*/
private $gender;
I have to hard code the values "male"
and "female"
. Is it possible to do something like this ?
choices = {self::GENDER_MALE, self::GENDER_FEMALE}
This is a feature of Doctrine2 Annotation Reader (Constants).
You solution: