Symfony2 表单验证
在我的实体中,我有一个像这样的字段:
/**
* @var decimal $Size
*
* @ORM\Column(name="Size", type="decimal", scale="2")
* @Assert\NotBlank()
* @Assert\Type(type="numeric")
*/
private $Size;
但是当我在创建表单中键入一个字符串(例如“foo”)时,函数bindRequest会抛出:
Expected argument of type "numeric", "boolean" given
500 Internal Server Error - UnexpectedTypeException
控制器代码是:
$request = $this->get('request');
if ($request->getMethod() == 'POST')
{
$form->bindRequest($request);
if ($form->isValid())
{
$em = $this->getDoctrine()->getEntityManager();
$em->persist($support);
$em->flush();
return $this->redirect($this->generateUrl('mediatheque_support_' . $shortcut . '_list'));
}
}
有什么想法吗?
谢谢
In my entity, I have a field like :
/**
* @var decimal $Size
*
* @ORM\Column(name="Size", type="decimal", scale="2")
* @Assert\NotBlank()
* @Assert\Type(type="numeric")
*/
private $Size;
But when I type a string, like 'foo' in the creation form, the function bindRequest throws :
Expected argument of type "numeric", "boolean" given
500 Internal Server Error - UnexpectedTypeException
The controller code is :
$request = $this->get('request');
if ($request->getMethod() == 'POST')
{
$form->bindRequest($request);
if ($form->isValid())
{
$em = $this->getDoctrine()->getEntityManager();
$em->persist($support);
$em->flush();
return $this->redirect($this->generateUrl('mediatheque_support_' . $shortcut . '_list'));
}
}
Any ideas ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定这不是预期的行为吗?您正在断言类型“numeric”并提供字符串“foo”...错误消息有点误导,但是说提供了“boolean”
Are you sure that isn't the expected behavior? You're Asserting a type "numeric" and providing a string "foo"... the error message is a little misleading however saying "boolean" provided