In Doctrine, there is no simple way to access the Doctrine object and get the status of the last attempt at inserting or updating the database. To overcome this glaring limitation of the DBAL (Database Abstraction Layer), we have to resort to older PHP techniques like using a try… catch condition.
Seems like a lot of code to do something we old-school PHP devs have been able to do with the mysql object for a decade now, but this is the reality of it.
try { $symfonyEntity= new symfonyEntity(); $symfonyEntity->setTitle('Symfony Entity Title'); $em = $this->getDoctrine()->getEntityManager(); $em->persist($dataObject); $em->flush(); $this->get('session')->setFlash('flashMsg',"Record inserted"); } catch (Exception $e) { $this->get('session')->setFlash('flashMsg',"Record not inserted"); }