vikmalhotra
vikmalhotra

Reputation: 10071

Implementing Database Error Handling in CodeIgniter

I am creating a webapp using codeigniter. I want to implement a error handling function. Say for example if I call a method of a model, and if an error occurs in that method, the error handler comes into action to return some pre-formatted string.

I was thinking of creating something like MY_Model, which every model class extends. Then, I can add the error handler in MY_Model class. But whether this can be done is beyond me right now. (yes I am a newbie at this)

Any enlightening ideas will help.

Regards

Upvotes: 1

Views: 2396

Answers (1)

user290102
user290102

Reputation:

What I tend to do is return an array instead of a boolean. This array contains 2 keys, 'return' and 'error'.

In case of an error this array will look like the following:

array('return' => FALSE, 'error' => 'Some error')

In case of a successful execution this array will look like the following:

array('return' => TRUE)

The controller then verifies these results and if there's an error it will display the one set in the 'error' key.

Upvotes: 3

Related Questions