Symfony实体验证

时间:2015-09-11 17:59:55

标签: php symfony entity

我正在使用symfony 2.7版本。 我尝试做验证,它的工作正常, 只是验证无效的消息。 例如,电子邮件验证:

 /**
 * @Assert\NotBlank()
 *      message = "Email empty";
 * )
 */
/**
 * @ORM\Column(type="string", length=100)
 */
protected $email;

我仍然收到默认消息: “这个值不应该是空白的。” 我重新创建实体文件,然后运行

php app/console doctrine:generate:entities AppBundle:User

仍然是默认消息。 我转过来  validation: { enable_annotations: true } 没有任何变化。 我看到错误,通过:

var_dump($errors);

因此,定制信息根本不起作用。

感谢

1 个答案:

答案 0 :(得分:1)

必须在括号之间写入消息选项:

/**
 * @Assert\NotBlank(
 *      message = "Email empty";
 * )
 * @ORM\Column(type="string", length=100)
 */
protected $email;