[英]Symfony2 : Validating a date using the Form Validator returns error
I've added a element to my form which is of type 'date', this then has a validation rule which specifies that the form element value must be of type date, otherwise return an error. 我在我的表单中添加了一个类型为'date'的元素,然后它有一个验证规则,它指定表单元素值必须是date类型,否则返回错误。 However rather than handling the validation, Symfony returns an Exception.
但是,Symfony不是处理验证,而是返回Exception。 See code below:
见下面的代码:
UserType.php UserType.php
$builder->add('startdate', 'date', array(
'label' => 'Start Date',
'widget' => 'single_text',
'format' => 'yyyy-MM-dd')
);
Validation.yml Validation.yml
Acme\StoreBundle\Entity\User:
properties:
startdate:
- Date:
message: You must specify a valid release date
Then when i type '2001-01-aaa' hoping that Symfony will notice the value is not in the right format and handle the error as specified, instead I get this 然后,当我键入'2001-01-aaa'希望Symfony会注意到该值不是正确的格式并处理指定的错误,而是我得到这个
Failed to match value '2007-01-aaa' with pattern 'yyyy-MM-dd'
500 Internal Server Error - InvalidArgumentException
Am I doing something wrong here? 我在这里做错了吗?
Thanks in advance 提前致谢
It's a bug. 这是一个错误。 It's now fixed and merged into 2.0 branch .
它现在已修复并合并为2.0分支 。 It'll be hopefully included in next minor version.
它有希望包含在下一个次要版本中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.