我试图通过 @Assert\Expression 在字段级别验证属性(http://symfony.com/doc/2.4/reference/constraints/Expression.html http://symfony.com/doc/2.4/reference/constraints/Expression.html).
它使用以下代码在类级别工作:
/**
* Foo
*
* @ORM\Table(name="foo")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity("slug")
* @Assert\Expression(
* "this.getPriceFor2PaxStandard() != null or (this.getPriceFor2PaxStandard() == null and !this.isPriceForAccLevelRequired('standard'))",
* message="The price for 2 pax standard is required",
* groups={"agency_tripEdit_finalsave"}
* )
*
*/
class Foo implements ISpellcheckerLocaleProvider, ProcessStatusAware, DataTransformer
{
但如果我在属性级别使用相同的代码(应该没问题)则不起作用:
/**
* @var decimal
*
* @ORM\Column(name="price_for_2_pax_standard", type="decimal", precision=16, scale=4, nullable=true)
* @Assert\Expression(
* "this.getPriceFor2PaxStandard() != null or (this.getPriceFor2PaxStandard() == null and !this.isPriceForAccLevelRequired('standard'))",
* message="The price for 2 pax standard is required",
* groups={"agency_tripEdit_finalsave"}
* )
*/
private $priceFor2PaxStandard;
另外,如果我使用也不起作用value
代替this.getPriceFor2PaxStandard()
当使用断言作为属性级别时。
任何提示将不胜感激:-)