how to access class variables and constants in annotation in symfony 2 php

后端 未结 1 820
闹比i
闹比i 2021-01-03 20:13

I have a class like this:

class Student {

const GENDER_MALE = \"male\", GENDER_FEMALE = \"female\";
/**
 * @var string $gender
 *
 * @ORM\\Column(name=\"gen         


        
相关标签:
1条回答
  • 2021-01-03 20:29

    This is a feature of Doctrine2 Annotation Reader (Constants).

    You solution:

    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 = {
         *          Student::GENDER_FEMALE: "Female",
         *          Student::GENDER_MALE: "Male"
         *      },
         *      message = "Choose a valid gender.", groups={"new"}
         * )
         */
        private $gender;
    }
    
    0 讨论(0)
提交回复
热议问题