如何在symfony 2 php中注释中的类变量和常量
发布时间:2020-12-13 16:30:35 所属栏目:PHP教程 来源:网络整理
导读:我有一个这样的课: class Student {const GENDER_MALE = "male",GENDER_FEMALE = "female";/** * @var string $gender * * @ORMColumn(name="gender",type="string",length=50,nullable=false) * @AssertNotBlank(message="Gender cannot be blank",group
我有一个这样的课:
class Student { const GENDER_MALE = "male",GENDER_FEMALE = "female"; /** * @var string $gender * * @ORMColumn(name="gender",type="string",length=50,nullable=false) * @AssertNotBlank(message="Gender cannot be blank",groups={"new"}) * @AssertChoice(choices = {"male","female"},message = "Choose a valid gender.",groups={"new"}) */ private $gender; 我必须硬编码“男”和“女”的价值观.有可能做这样的事情吗?
这是
Doctrine2 Annotation Reader (Constants)的一个特点.
你的解决方案 class Student { const GENDER_MALE = "male",GENDER_FEMALE = "female"; /** * @var string $gender * * @ORMColumn(name="gender",nullable=false) * @AssertNotBlank(message="Gender cannot be blank",groups={"new"}) * @AssertChoice( * choices = { * Student::GENDER_FEMALE: "Female",* Student::GENDER_MALE: "Male" * },* message = "Choose a valid gender.",groups={"new"} * ) */ private $gender; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |