Debugging Zend Framework using firebug

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 :D

First install the FirePHP add-on for your Firebug. Then you can use the following snippet anywhere to dump your variables to firebug console -

$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log( $writer );
$logger->log('My Sample Log', Zend_Log::DEBUG);

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 -

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

Instead of using these constants, you can also use these methods -

$logger->info('My Sample Log');
$logger->warn('My Sample Log');
$logger->err('My Sample Log');

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

protected function _initLogger() {
 $writer = new Zend_Log_Writer_Firebug();
 $logger = new Zend_Log( $writer );

 Zend_Registry::set( 'logger', $logger );
}

Now we can log our variables, arrays or anything from anywhere by writing this -

Zend_Registry::get('logger')->info('my variable');
Zend_Registry::get('logger')->warn('my variable');
Zend_Registry::get('logger')->err('my variable');

It’s easy, isn’t it? :D

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

4 thoughts on “Debugging Zend Framework using firebug

  1. ["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)

    ]

Leave a Reply