How to show an alert message on delete of parent node in symfony2 instead of exception page? [closed]
You can catch a ForeignKeyConstraintViolationException
exception and display a flash message to the user.
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;// Action$em = $this->getDoctrine()->getManager();$user = $em->getRepository('AppBundle:User')->find($id);try { $em->remove($user); $em->flush(); $this->addFlash('success', 'User removed');} catch (ForeignKeyConstraintViolationException $e) { $this->addFlash('error', "This user has connected services, so it can't be removed.");}