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
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.