I am using Symfony and creating a soft with 3 tiers (client, apache, mysql). So I don't know how to get the statut when the symfony application persists and flushs something?
When I add something in database I display an alert like "Add done!" but if my database is down I will display "Add done" despite the fail...
So how can I get the statut of these functions (flush/persist)? How can I change my alert switch the statut?
Best regards,
Use a try & catch block:
try {
$article = new Article(); //Example entity
$em = $this->getDoctrine()->getEntityManager();
$em->persist($article);
$em->flush();
$this->get('session')->setFlash('flash_key',"Add done!");
} catch (Exception $e) {
$this->get('session')->setFlash('flash_key',"Add not done: " . $e->getMessage());
}
In case you get errors try using "\Doctrine\ORM\ORMException $e", \Doctrine\DBAL\DBALException $e" or "\Exception $e" inside catch()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With