通常我在所有基于注释的地方使用 Constants
,例如注释、路由和断言注释
,但在 Assert\Expression 中它抛出 Variable "EntityInterface"is not valid around position 26.
这是一个错误还是一种特殊的罕见情况?
<?php
/**
* @var string
*
* @ORM\Column(name="id_number", type="string", length=11, nullable=true)
* @Assert\Expression(
* "this.getNationality() == EntityInterface::COUNTRY_DEFAULT_VALUE and value != null",
* message = "form.user.validation.id_number.blank",
* groups = {"personal_info"}
* )
* @Assert\Regex(
* pattern="/^([\d]{11})$/",
* match=true,
* message="form.user.validation.id_number.regex",
* groups = {"personal_info"}
* )
*/
private $idNumber;
最佳答案
尝试使用
/**
* @ORM\Column(name="id_number", type="string", length=11, nullable=true)
* @Assert\Expression(
* "this.getNationality() == constant('EntityInterface::COUNTRY_DEFAULT_VALUE') and value != null",
* message = "form.user.validation.id_number.blank",
* groups = {"personal_info"}
* )
*/
相反(省略了您示例的部分内容以专注于在此处使用 constant()
)。
引用,见
关于php - Symfony2 Assert\Expression 注释不支持常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34479270/