开发者

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜