Using FirePHP-Helper as a Debugger on CodeIgniter
FirePHP is a debugger to output/print any values to firebug console. Some nice features that you can use are message, label, and code tracing. If you usually use
var_dump to develop PHP apps, FirePHP is a much handier for you.
In this tutorial, we will cover how to use FirePHP via CodeIgniter helper. This method is much simpler than using class. You just drop firephp_helper.php and firephp library, then use autoload or load
$this->load->helper('firephp') to call it, and call
function fire_print() on-the-fly. For further details, let’s see how it goes!
Values, that you can pass, will be as string, array, object, json, or xml.
- Install Firebug on Firefox or Firebug lite on google chrome.
- Get FirePHP libs
- Put FirePHP libs on
- Get helper on http://gist.github.com/3749507. Put it on
And your file structure should look like this:
There are two ways to load this helper. You can add to
application/config/autoload.php, or just open controller or model. If you haven’t put it on the autoload helper, you can use:
The FirePHP function parameter structure can be the following:
$log_type could be: ‘log’, ‘info’, ‘warn’,’error’; $data could be: ‘string’,’array’,’object’,’json’,’xml’; Fire_print($log_type, $data)
Open Firebug on your browser, then open the tab 'console'. Or, you can right click on
web page -> inspect element -> console
On the php code call:
And the Firebug console should look like this:
Click on the console result to open the variable viewer.
Now, let’s try to output json and object.
json : using FirePHP to view data from twitter STREAMS API.
object : use FirePHP to see the output of objects from CodeIgniter Datamapper
Tracing code execution:
This FirePHP-helper is so much useful than the
var_dump or print_r. It gives you the easier way to see the output and give label on
log/warn/error, and is truly helpful for viewing the object and json data. This FirePHP-helper is also a great tool to see ORM/Datamapper object output, or RESTful API client, such as Facebook or Twitter.
Author: Olivo Pablo