0
我不知道如何將錯誤重定向到一個窗體,如果它不符合Symfony2?如果在Symfony2中無效,如何重定向到帶有錯誤的窗體?
所以我使用斷言在我的實體那樣:
/**
* @ORM\Column(type="string", length=255, nullable=false)
* @Assert\NotBlank()
*/
private $title;
這是我createAction方法:
public function createAction(Request $request)
{
$task = new Task();
$form = $this->createForm(new TaskType(), $task);
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$em->flush();
}
// What should I do here if the form is not valid
$this->get('session')->getFlashBag()->add('success', 'The task has been added successfully!');
return $this->redirect($this->generateUrl('crm_tasks'));
}
return $this->render('LanCrmBundle:Task:create.html.twig', array(
'form' => $form->createView(),
));
}
我應該怎麼做錯誤返回到窗體?
感謝您的回答。 – user3064931