开发者

Symfony2 form validation

开发者 https://www.devze.com 2023-04-05 11:33 出处:网络
In my entity, I have a field like : /** * @var decimal $Size * * @ORM\\Column(name=\"Size\", type=\"decimal\", scale=\"2\")

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 ?

Tha开发者_如何学编程nks


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

0

精彩评论

暂无评论...
验证码 换一张
取 消