2
通常我在所有基于注释的位置使用Constants
,例如, annotations, route and assert annotations
,但是在Assert \ Expression中抛出Variable "EntityInterface" is not valid around position 26.
这是一个错误还是特殊的罕见情况?Symfony2 Assert Expression注释不支持常量
<?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;
它不工作,它说'警告:常数():无法找到固定EntityInterface :: COUNTRY_DEFAULT_VALUE'我检查常量在那里。 – FZE
好的我发现这个问题需要名称空间抱歉。 FrontendBundle \\ EntityInterface :: COUNTRY_DEFAULT_VALUE现在可以。 – FZE
确实@FZE它看起来像常量函数()不能读取使用语句,并需要转义: @ @ assert \ Expression(“!(this.foo ==常量\\富::巴)“) 不像其他约束像范围例如: 使用的AppDomain \模型\富\富; @assert \范围(MIN =美孚:: MIN_NUMBER) – webDEVILopers