How do you debug CodeIgniter applications? How do you debug CodeIgniter applications? codeigniter codeigniter

How do you debug CodeIgniter applications?


A good practice is to enclose critical code into try/catch blocks so that you can handle exceptions, and then log the stack trace of that error. In my recent experience, I've used try/catch blocks along with show_error() function provided by CodeIgniter to debug and catch errors in my code. Here's an example:

public function getData()   {     //Query the data table for every record and row     try{        $query = $this->db->get('accounts');        if ($query->num_rows() > 0)        {            show_error('Database is empty!');        }       else       {           return $query->result();       }     } catch(Exception $e){        log_message('debug',$e->getMessage()); // use codeigniters built in logging library        show_error($e->getMessage()); // or echo $e->getMessage()      } }

PHP Exception class provides various methods to help debug your error. http://www.php.net/manual/en/class.exception.php


You can use Xdebug and it's a good idea to start with Test Driven Development, in PHP you can use PHP Unit for that.


If you've not already looked at the amazing web development extension for firefox called Firebug you should check it out!

Firebug has an extension called FirePHP which enables you to debug PHP applications. Someone has also made an plugin fore CodeIgniter called FireIgnition.

It enables you log variables and so forth making it easier to see what is going on as pages are being executed.