我有一个这样的课程:
Warning messages:
1: In `[.data.table`(demographic1, , `:=`(paste0("F", i), ... :
RHS 1 is length 2 (greater than the size (1) of group 1). The last 1 element(s) will be discarded.
我必须对值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;
和"male"
进行硬编码。可以这样做吗?
choices = {self :: GENDER_MALE,self :: GENDER_FEMALE}
答案 0 :(得分:31)
这是Doctrine2 Annotation Reader (Constants)的一项功能。
你解决方案:
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;
}