Featured Post

Browse Internet with pleasure

We live in freedom time. Most people spend their lives in free coutries, they can make free choices, do just what they want. The same should be with Internet browsing. We can choose our favourite browser and view webpages we like. The problem is that me and probably most of you had some bad experiences...

Read More

Integrating FirePHP with Zend Framework 2

Posted by Tomasz Kuter | Posted in Programming, Web development | Posted on 22-03-2013

Tags: , , , , , , , , , , , , ,

1

In this post I will show you how to easily integrate FirePHP – Mozilla Firefox extension with Zend Framework 2. FirePHP enables you to log to your Firebug Console using a simple PHP method call. All data is sent via response headers and will not interfere with the content on your page. FirePHP is ideally suited for AJAX development where clean JSON and XML responses are required.

General information

At the beginning some basic notes:

So download server side version and unpack the archive.
Find the FirePHPCore inside and copy it to /vendor/firephp directory.

At this step you should have FirePHP.class.php in the /vendor/firephp/FirePHPCore/.

Now rename FirePHP.class.php to FirePHP.php.

Once you successfully installed FirePHP extension in Mozilla Firefox you can get to next step – setting up the Zend\Log in our tutorial application.

Setup Zend\Log

File /config/autoload/global.php should look like:

As you could notice – we have two writers:

  • FirePhp,
  • and Stream.

Stream writer needs appropriate directory permissions to be able to write in the /data/log directory.

And this should be all. You can check the Firebug console if you successfully see the message from the FirePHP:

Logging debug messages

To use FirePHP in your code you need to get Zend\Log instance and execute one of following methods on the Log object:

  • $log->info(‘info message’);
  • $log->crit(‘critical error message’);
  • $log->err(‘error message’);
  • $log->warn(‘warning message’);
  • $log->notice(‘notice message’);
  • $log->debug(‘debug message’);

So let’s check it in Album controller:

FirePHP enabled

FirePHP enabled

Advanced usage of FirePHP

More FirePHP options: e.g. grouping, data labeling, etc you can find on the following page:
http://www.firephp.org/HQ/Use.htm

All the code you can download from the below link:
https://github.com/evolic/zf2-tutorial/tree/release-0.3.2

Update

Integrating FirePHP library with Zend Framework 2 can be much more simple. All you need to do is to modify Composer configuration file. More info in another post of this blog.

Comments (1)

Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting identical rss problem? Anyone who knows kindly respond. Thnkx

Write a comment