How to Catch exception in the controller and show flash message in Symfony 2?
try{
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('target page'));
} catch(Exception $e){
// What to do in this part???
}
return $this->render('MyTestBundle:Article:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
What should I do in the catch
block?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…