【发布时间】:2014-08-30 05:52:24
【问题描述】:
我正在尝试通过@Assert\Expression (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(),也不起作用。
任何提示将不胜感激:-)
【问题讨论】:
标签: validation symfony assert