There are conditions when we need to show sql error messages to users such as Duplicate Entries from database.
For example in cakephp, if there is duplicacy error from database then it will show following message to the user:
"Database Error Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry"
To show proper message instead of this then you need to display information and use a view. To pass information from the controller to the view use the set method. In order to do so write the following code:
$this->set('errormsg', $e->getMessage());
If you want to use AJAX you can set it like this:
$this->set('_serialize', array('errormsg'));
Thanks for reading the blog.
0 Comment(s)