【发布时间】:2012-05-01 09:42:56
【问题描述】:
我正在继续研究 Symfony2,发现新的“问题”!
让我描述一下这个问题。 我有一个在 Doctrine Entity 上构造表单的类。它与this page of the official docs 中描述的注册表单示例相同。唯一的区别是我使用 Doctrine 而不是 MongoDB。
现在,我在 User 类中添加了以下字段
/**
* @Assert\Type(type="integer", message="Not an integer.")
* @ORM\Column(type="smallint", name="num")
*
* @var Smallint $num
*
*/
protected $num;
然后,我通过添加以下行更新了类 UserType 中的函数 buildForm:
public function buildForm(FormBuilder $builder, array $options)
{
...
$builder->add('num', 'integer', array(
'label' => 'Insert a number',
));
}
这就是问题所在。尽管我通过 Annotation 提供了自定义消息,但字段 num(即字符串值)的错误输入会返回以下错误代码:“This value is not valid”而不是“不是整数”。
对自定义错误消息的这种遗漏解释有什么想法吗?
【问题讨论】:
标签: forms symfony annotations doctrine-orm validation