Debugging a CodeIgniter application with FirePHP

FirePHP is an addon for FireBug extension for Firefox browser.

FirePHP extends FireBug functionalities to show log or error messages coming from your PHP application. These messages won’t be printed on the application interface but instead on the FireBug console.

What do you need to integrate this debugging feature in your application :

  1. Firefox browser
  2. FireBug extension
  3. FirePHP extension

The next step is to open Firefox and visit the url where your application is located and activate the Net panel in FireBug, clicking the bottom right Firebug icon in Firefox window.

FireBug Net Panel

The client (the browser), is now ready to accept the debugging messages, we have now to integrate the FirePHP library with the CodeIgniter application on server side :

  • dowload the FirePHP Core Library from here
  • extract the FirePHP.class.php from the archive, rename it to firephp.php and copy in the system/application/libraries directory of your CodeIgniter application

Now you can use FirePHP to debug your code :

  • load the library : $this->load->library('firephp')
  • send debug messages to the FireBug console : $this->firephp->log($myvariable) or $this->firephp->error('Error at this line')

Detailed instructions to use FirePHP are available on FirePHP project website. The most useful method for me are :

  • $this->firephp->log($myvariable) : send a dump of the variable $myvariable on the FireBug console
  • $this->firephp->warn($myvariable) : send a dump of the variable $myvariable on the FireBug console classified as a warning
  • $this->firephp->error($myvariable) : send a dump of the variable $myvariable on the FireBug console classified as an error

Here there is a little example on how you can use FirePHP with CodeIgniter :

 

And this is the output on the Firefox’s FirePHP console :
FirePHP console

The debug messages can be disabled with the method : $this->firephp->setEnabled(FALSE).
It is also possible to make the messages appear only for specific ip addresses :

 

Suggested books

CodeIgniter for rapid PHP application developmentCodeIgniter 1.7 Professional Development

, , ,

25 Responses to Debugging a CodeIgniter application with FirePHP

  1. Daniel15 May 23, 2009 at 12:09 #

    “load the library : $this->load->library(‘pdf_label’)”
    I think you mean to load FirePHP, not pdf_label ;)

  2. Roberto May 23, 2009 at 13:34 #

    Corrected, many thanks.
    I’ve been working also on integration of FPDF library in CodeIgniter at the same time ;)

  3. Ivan June 5, 2009 at 13:22 #

    Hello,
    I installed firephp, but seems like my server absolutely refuses to send the firephp headers… so it’s not working. I tried it outside CI also, but it doesn’t work. I’m stuck..
    Do you have any idea where the problem can be?

    Thank You :>

  4. Ivan June 5, 2009 at 16:34 #

    Seems line IT IS working, but only on windows.. I was based on the lack of headers, but trough FireBug, which is working but is also broken. So the problem is somewhere there > http://groups.google.com/group/firebug/browse_thread/thread/7c1a9c0886d98070/6791b68e3a829ceb

  5. Eliecer Hdz Garbey (A.K.A EliuX) June 11, 2009 at 21:01 #

    Hi I think its very interesting your article put the most important for me is to debug step by step in a IDE like Aptana, Zend Studio for Eclipse or others. My question is: What IDE for PHP can debug a MVC framework like CodeIgniter? The only framework with this capability in the market is Zend framework because it works with Zend Studio for Eclipse thats hides how it do this and has many cute things like whole perspective for Zend applications….
    Now am making an complex Ajax application with Ext JS and CodeIgniter; and Aptana is the best untill now thats make the best intelisence for Ext JS (and many others Javascript libraries) and I have got It do the same with CodeIgniter, with Zend Studio for Eclipse I have got none good integration with Ext JS library but it does better integration that Aptana for CodeIgniter, even got that make me the clases by the menu option. I suppose that many of you has problems like this, and I would like somebody tells me if makes advances in things like this but mainly debugging MVC(Model-View-Controller) php applications, any thing I could help write me to my mail. Thanks

  6. Roberto June 11, 2009 at 21:10 #

    Hi Eliecer.
    I don’t use any IDE to develop, but only gedit with some extensions (my operating system is Ubuntu).
    Perhaps you could consider a more sophisticated debugging system like Xdebug. See here how to use Xdebug with Eclipse.

  7. Brad July 26, 2009 at 12:43 #

    Try PHP Designer by http://www.mpsoftware.dk/ to edit your code. it’s fairly good with the MVC code.. As with anything it could be better, but the developer who wrote my website (In CI) loves it.

    -Brad

  8. Roberto July 26, 2009 at 16:01 #

    Hi. Many thanks for the suggestion.
    Roberto

  9. Stas February 16, 2010 at 16:40 #

    Hi.

    I suggest to try free PHP IDE – Codelobster PHP Edition with own PHP debugger. It has also very useful special CodeIgniter plug-in.

    Stas.

  10. jon June 21, 2010 at 15:12 #

    hi, nice tutorial,
    i wanted to add that i had to update from 3.0.1.6 firefox to 3.6 and upgrade firebug
    before firephp would display headers correctly.

  11. Darwin July 30, 2010 at 12:48 #

    I am trying Code Lobster for Codeigniter
    Will post my experience here after my testing.

  12. Tijhaart November 13, 2010 at 22:40 #

    Hey, thanks for the info.

  13. Anonymous July 15, 2012 at 18:17 #

    The debug messages can be disabled with the method : $this->firepgp->setEnabled(FALSE).

    You mean $this->firephp, not $this->firepgp

Trackbacks/Pingbacks

  1. Debug CodeIgniter AJAX applications with FireIgnition | jigniter™ - July 26, 2009

    [...] Debugging a CodeIgniter application with FirePHP. [...]

  2. Debuggare applicazioni Codeigniter con FirePHP, FireBUG, Debugging PHP, Firefox componenti aggiuntivi per php | Programmazione Web - July 29, 2009

    [...] http://www.firephp.org/ http://speedtech.it/2009/05/debugging-a-codeigniter-application-with-firephp/ (Non ci sono voti)  Loading … Poi seguire le risposte tramite RSS 2.0 feed. Puoi [...]

  3. 40+ CodeIgniter Framework Tutorials for Kick-Ass PHP Application | 2experts Design - Web Design and Graphic Design Blog - October 16, 2009

    [...] 8. Debugging a CodeIgniter application with FirePHP [...]

  4. 40+ CodeIgniter Framework Tutorials for Kick-Ass PHP Application | PHP Frameworks - October 16, 2009

    [...] 8. Debugging a CodeIgniter application with FirePHP [...]

  5. 40+ CodeIgniter Framework Tutorials for Kick-Ass PHP Application | Son Of Byte - November 3, 2009

    [...] 8. Debugging a CodeIgniter application with FirePHP [...]

  6. Getting Started with CodeIgniter and How to Create All Those Great Apps | DevSnippets - February 23, 2010

    [...] – Debugging a CodeIgniter application with FirePHP [...]

  7. Getting Started with CodeIgniter and How to Create All Those Great Apps « Web Development News - March 11, 2010

    [...] – Debugging a CodeIgniter application with FirePHP [...]

  8. Getting Started with CodeIgniter and How to Create All Those Great Apps | PHP Lovers - May 7, 2010

    [...] – Debugging a CodeIgniter application with FirePHP [...]

  9. 40+ CodeIgniter Framework Tutorials for Kick-Ass PHP Application - June 7, 2010

    [...] 8. Debugging a CodeIgniter application with FirePHP [...]

  10. 40+ CodeIgniter Framework Tutorials for Kick-Ass PHP Application | Hassan C - June 20, 2010

    [...] 8. Debugging a CodeIgniter application with FirePHP [...]

  11. مواقع مفيدة لتعلم اطار العمل codeigniter php - July 10, 2010

    [...] 8. Debugging a CodeIgniter application with FirePHP [...]

  12. Debugging a CodeIgniter application with FirePHP | CodeIgniter Tutorials - May 20, 2011

    [...] Series andrewroland zend lucene librarycodeigniter 2.0 workshoplearncodeigniter basicssimplycodeigniter flashdatasimplycodeigniter login form Sponsors SocialTop Rated TutorialsCodeIgniter Active Record class and INSERT IGNORE (2 votes)Getting Started With CodeIgniter URL Routing (2 votes)Using Elliot Haughin's Twitter API with Codeigniter Part 2 (2 votes)Codeigniter Project Development from scratch to app Part 6 (2 votes)Tags2.0 active record ajax amplio.ch andrewroland.com api askaboutphp beginner class codesamplez controller darrenonthe.net db dragffy.com error flashdata form from scratch geekhut.org helper html innovativephp install javascript jquery library login model multiple MVC net.tutsplus post reactor registration session simplycodeigniter string twitter upload URL validation view views workshop zend Sponsors LinksDebugging a CodeIgniter application with FirePHP [...]