What do you think is the best way to catch all doctrine 1.2 ORM exceptions in codeigniter framework, i would not like to wrap the entire index.php with a try catch, but neither to do a try catch before and after every query,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, first, you’ll have to wrap around only single line in
index.php. And actually, this might be good in case you have exceptions you don’t want to show (e.g. in production environment).The second point here is that your database-related code should be concentrated in models. So you might introduce helper class, which is something like
Than you’ll just replace
$query->execute($params,$hydration)in all your models toSafeQueryHelper::safeQueryRun($query,$params,$hydration). Don’t forget to load it with$this->load->helper('SafeQueryHelper')or through the config.For record methods like
updateanddelete– you’ll have to wrap it intry .. catch.Well, and if you don’t have your database-related logic concentrated in models… That changes nothing, actually, but that means that you have poorly-designed application that violates the essential priinciple of
MVCpattern, so start refactoring.The last possible solution – is to hack into Doctrine core classes (specifically into
Doctrine_Connection) and wrap intotry ... catchlines that perfrom actual quering. But that’s a bad idea, I really wouldn’t do that.A little update: as all Doctrine entity objects are subclaeses of
Doctine_Recordyoumay extendSafeQueryHelperwith methods for wrappingsave,deleteetc:Than replace
$entity->save()withSafeQueryHelper::SafeSave($entity)