PHP디버깅 – 코드이그이터 (Debugging a CodeIgniter application with FirePHP), Firebug, FirePHP

http://speedtech.it/blog/2009/05/10/debugging-a-codeigniter-application-with-firephp/

오 친절하게 설명이 잘되어있구만… 2009년도 글이네 -_-;

Debugging a CodeIgniter application with FirePHP

by  on May 10, 2009 in General

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 thesystem/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

Leave a Reply

Your email address will not be published.