You can use firebug to debug your Zend Framework application. May be you are using print_r(), var_dump() or Zend_Debug::dump($var), they prints the information in your application. But, with the help of FirePHP add-on for Firebug, we will be able to dump our variable on firebug console 😀
First install the FirePHP add-on for your Firebug. Then you can use the following snippet anywhere to dump your variables to firebug console –
[sourcecode language=”php”]
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log( $writer );
$logger->log(‘My Sample Log’, Zend_Log::DEBUG);
[/sourcecode]
The second parameter of the Zend Logger is a constant. You can use 0-7 (zero to seven) as a parameter. Here is the details –
[sourcecode language=”php”]
Zend_Log::EMERG = 0; // Emergency: system is unusable
Zend_Log::ALERT = 1; // Alert: action must be taken immediately
Zend_Log::CRIT = 2; // Critical: critical conditions
Zend_Log::ERR = 3; // Error: error conditions
Zend_Log::WARN = 4; // Warning: warning conditions
Zend_Log::NOTICE = 5; // Notice: normal but significant condition
Zend_Log::INFO = 6; // Informational: informational messages
Zend_Log::DEBUG = 7; // Debug: debug messages
[/sourcecode]
Instead of using these constants, you can also use these methods –
[sourcecode language=”php”]
$logger->info(‘My Sample Log’);
$logger->warn(‘My Sample Log’);
$logger->err(‘My Sample Log’);
[/sourcecode]
Now, the problem is, when you are going to dump any variable to the console, the pain in the ass is to instantiate the logger Zend_Log_Writer_Firebug and Zend_Log. So lets add them to our Bootstrap.php to add them as default logger. Add this little function to your Bootstrap.php
[sourcecode language=”php”]
protected function _initLogger() {
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log( $writer );
Zend_Registry::set( ‘logger’, $logger );
}
[/sourcecode]
Now we can log our variables, arrays or anything from anywhere by writing this –
[sourcecode language=”php”]
Zend_Registry::get(‘logger’)->info(‘my variable’);
Zend_Registry::get(‘logger’)->warn(‘my variable’);
Zend_Registry::get(‘logger’)->err(‘my variable’);
[/sourcecode]
It’s easy, isn’t it? 😀
Logging with other options:
You can add any debug helper, like
- error_log file
- sending errors via email
- error logging to database
- writing errors to system log
- writing log to zend server monitor
It’s nothing, but just add those debug writers on our newly created _initLogger function at Bootstrap.php and add them to Zend_Log, like we did for Zend_Log_Writer_Firebug. For more info, visit here
[“There was a problem wri…ePHP/FirebugConsole/0.1”,
TypeError: node is undefined
[Bei diesem Fehler anhalten]
Filtered chrome url chrome://firebug/content/lib/domplate.js
domplate.js (Zeile 515)
]
–> For FF9 + you need to install FirePHP Extension 0.7.0rc2 (http://www.firephp.org/).
You are the only person who has properly documented this topic, no where I found properly except you. Thank you.
nice blogs
thanks for halp