我可以通过@ORM注释生成验证规则吗



考虑这个条令实体

class Product 
{
     /**
      * @ORMColumn(type="string", length=24, nullable=false)
      */
     private $title;
}

我可以通过@ORM注释以某种方式生成@Asserts注释吗。所以在这一代人之后,我会上这门课。

class Product 
{
     /**
      * @AssertNotBlank()
      * @AssertLength(max="24")
      *
      * @ORMColumn(type="string", length=24, nullable=false)
      */
     private $title;
}

您不能自动执行。但可以为其创建自定义生成器。

或者,您可以创建自定义验证器,基于ORM映射验证实体;

最新更新