Setup ZFDebug for Debuging your Zend Framework Project

“ZFDebug is a plugin for the Zend Framework for PHP5, providing useful debug information displayed in a small bar at the bottom of every page.”

 

We just need two steps to setup ZFDebug:

 

1. Download it from https://github.com/jokkedk/ZFDebug, place it inside library just next to Zend Framework

 

 

2. Modify application/Bootstrap.php to add initialized function:

 

/**
 * include ZFDebug console in development environment
 */

protected function _initZFDebug()
{
    // normally only section [development] has the "zfdebug" option
    if ($this->getOption('zfdebug')) {
        // namespace "ZFDebug" for autoloader
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('ZFDebug');

        // initialize front controller
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');

        // enable zfdebug options
        $options = array('plugins' => array(
            'Variables',
            'Memory',
            'Time',
            'Registry',
            'Exception',
        ));

        // add caching backend option if specified
        if ($this->hasPluginResource('cache')) {
            $this->bootstrap('cache');
            $cache = $this->getPluginResource('cache')->getDbAdapter();
            $options['plugins']['Cache']['backend'] = $cache->getBackend();
        }

        // add db option if specified
        if ($this->hasPluginResource('db')) {
            $this->bootstrap('db');
            $db = $this->getPluginResource('db')->getDbAdapter();
            $options['plugins']['Database']['adapter'] = $db;
        }

        // register ZFDebug with front controller
        $zfdebug = new ZFDebug_Controller_Plugin_Debug($options);
        $front->registerPlugin($zfdebug);
    }
}

 

And that’s all, now you should see a debug bar just at the bottom of your project like this:

 

Posted in Zend Framework | Tagged , | Leave a comment