Upsss… it’s 1 hour after midnight, still not sleeping. Hopefully I’ll manage to wake up in the morning, since I’m working. Anyhow… here’s a little something I made for you guys (for those who find it useful).
I was playing around with Zend Framework today, checking out available classes and methods. My eyes filled with yoj when I came across Zend_Wildfire_Plugin_FirePhp class. It’s located under /Zend/Wildfire/Plugin/FirePhp.php folder in ZendFramework. It’s around 600 hundred lines or so. What’s cool about this class is that it has this cool method you can use to shoot out messages to FireBug. If my info is correct, this class is added to ZendFramework from version 1.6. As of time of this writing, latest version of Magento is 1.2.0.1 and it comes packed with ZendFramework 1.7.2 which is also the latest version as of time of this writing. So, there you go, bingo. We now have this cool little class that can save as a bunch of time (or not).
My point is, the PHP debugging solution generally suck. I know, it’s a hard word, and I like to avoid statements like that as much as I can, but sometimes the feeling just take you over
I wrote a little function that you can use in Magento to output messages to FireBug. This, off course, is just my version of doing things. Feel free to implement some different solution if you find my lacking in some aspect.
Here is my function
/**
*
* @author Branko Ajzele
* @license GPL
*
* @param object $var Object we wish to debug in FireBug
* @param string $label Nice little label we wish to add so we can see it in FireBug
* @param string $style String holding one of values: ‘LOG’, ‘INFO’, ‘WARN’, ‘ERROR’, ‘TRACE’, ‘EXCEPTION’, ‘TABLE’
* @return void Return null if Mage::setIsDeveloperMode(false) otherwise return message to browser
*/
function acl($var, $label, $style = ‘LOG’)
{
if(Mage::getIsDeveloperMode())
{
$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();
$channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
$channel->setRequest($request);
$channel->setResponse($response);
/*
* Start output buffering
*/
ob_start();
Zend_Wildfire_Plugin_FirePhp::send($var, $label, $style);
/*
Style Description
LOG Displays a plain log message
INFO Displays an info log message
WARN Displays a warning log message
ERROR Displays an error log message that increments Firebug’s error count
TRACE Displays a log message with an expandable stack trace
EXCEPTION Displays an error long message with an expandable stack trace
TABLE Displays a log message with an expandable table
*/
/*
* Flush log data to browser
*/
$channel->flush();
$response->sendHeaders();
}
else
{
return null;
}
}
All you need to do is to place it inside the index.php file, the one inside the root Magento folder. You need to place it after Mage::setIsDeveloperMode(true); statement. Which by the way you need to uncomment (in development environment). That’s it, your done.
Now all you need to do is go into one of your template files like /catalog/product/view.phtml and call this function like
acl($this->debug(), ‘Product view page aka view.phtml VAR: $this’);
or
acl($_product->debug(), ‘Product view page aka view.phtml VAR: $_product’);
I provided a screenshot below for you to see the result of the two function calls.
And here is the full version of my index.php file.
To summarize. For this to work you need
- Firefox with installed FireBug and FirePHP
- Copy – Paste my function from above to your index.php file
- Just call acl() function with appropriate params inside one of your template files
Although this may not be the “happiest” soultion, since some messages get duplicated in FireBug if you call acl function from controllers, hope some of you find this useful.

This is a great find. Seems like it would be best to work this into an extension of some kind which would allow you to enable various debug statements based on an administrative set of check boxes.
I noticed in your screenshot that you don’t have the zend studio firefox debugger extension installed. Have you tried that out?
http://www.zend.com/en/products/studio/downloads
select “studio web debugger”
T
@Tony
sorry, it’s “Studio Browser Toolbar” then select “cross platform firefox” or “IE for windows”.
Hi Tony,
Thnx for the tip. It’s just that I work across various computers, and the only thing they have in common is Firefox
so the above approach seems satisfying.
I’ll be sure to test out the Zend debugg toolbar… It’s already installed, I just hide the toolbar
For sure, this is a great post. I haven’t used the zend debugger toolbar either. I’m following your series on zend studio and before that netbeans. I’m on the same computer all day everday. What distro is that you’re running btw?
It’s latest openSuse 11.1… although I see no big significant difference between other distros. It’s mostly a showoff for friends… KDE 4 looks quite candy
I’d just like to say thanks for this article. Even though it’s not my first day with PHP and I already have FireBug, I had no idea the whole FirePHP thing existed. This is a lifesaver with magento where the old-school “echo” debug method just isn’t gonna cut it.
nice tricks !! thanks for sharing this.. i was using the var_dump to output the var to the browser but sometimes the magento application is stuck
There is also PHPEdit, which has a PHP debugger and a Firefox extension.
Thnx for the input Nightfly.
I must say I get chills when someone mentions PHP and integrated debugger in same sentence.
Good luck using any IDE’s debugger with Magento.
I’m really sorry if I sound a bit sarcastic, it’s just that I lost countless hours on trying to setup NetBeans and ZendStudio to work with the XDebug. All I got was my Apache crashing on every second page load, and the depth of debugging was hilarious. Every more complex classes and functions caused failure of debugger.
I finally end up using FireBug and var_dump combinations.
I would really appreciate if you can share some link or article that describes in detail the process of debugging platforms like Magento.
Thank you.
In the beginning PHP debugging was a nightmare, but with modern PHPEdit http://www.phpedit.com/ its Firefox extension http://www.waterproof.fr/blog/index.php?/archives/27-New-firefox-extension.html and XAMPP it’s a breeze.
I basically install XAMPP, enable xdebug with default settings in the php.ini, disable Zend extensions (Loader etc.), install PHPEdit and the Firefox extension, create a project, set a breakpoint eg. in index.php, tick the “enable debugging” button in Firefox, load the Page and a few seconds later the PHPEdit debug session has started.
Also, thanks for the article, FirePHP is really a great help for Magento development! I’m just coding a backend module and it helps a lot to debug models and so on.
BTW, XAMPP 1.7.0 doesn’t work with Magento (MySQL PDO is broken) unless you fix it up with the solution presented here: http://www.apachefriends.org/f/viewtopic.php?f=16&t=32617
Hi branko,,
i wanted to know why after enabling log from admin panel also i m unable to find any log file in basedir\var\
is there any other setting i need to do???
There’s a debug module here: http://www.magentocommerce.com/extension/reviews/module/949/debug-module
…but I’ve yet to be able to get it to install. Hopefully it will be working soon though, without the need for a workaround at least.
as a follow up, use this key and it works fine (even though it didn’t work with the dropdown set to beta):
magento-community/Netresearch_Debug-beta
BTW I just tried Firefox 3.5, which has the new Tracemonkey optimizing JS engine. With javascript.options.jit.chrome option set to true, even large FirePHP logs (such as almost any Magento class) can now be handled without waiting half an hour on FirePHP or Firefox crashing.
Great article Branko, thanks very much!.
I have followed your steps but can't seem to get any output in firebug. Is there some setting I need to change in firebug or firephp? I'm not getting any errors and I have magento set to developer mode. Thanks.
thank you very much. I wrote your function in the class Mage. This feature is very helpfu
i need a list box in the check out form..that shud record in the admin panel..as like every other field does..
how do i do this?
i need a list box in the check out form..that shud record in the admin panel..as like every other field does..
how do i do this?
Merry Christmas! From November onwards, it is impossible to forget that Christmas is coming. Coloured lights decorate many town centres and shops, along with shiny decorations, and artificial snow painted on shop windows. In streets and shops, 'Christmas trees' (real or plastic evergreen 'conifer' trees) will also be decorated with lights and Christmas ornaments.
I've tried a lot..in debugging Magento Using Eclipse and finally I was able to do.. Here's the link you might like to give a look.
http://subesh.com.np/2010/01/debugging-magento-...
Were you ever able to figure this out? I am having the same problem where I followed Branko's steps exactly but can't seem to get any output in Firebug (no errors). Is there any set up that needs to be done with FirePhp besides installing it?