My favorites | Sign in
Project Logo
                
Search
for
Updated Sep 21, 2009 by gugakfugl
Labels: Featured
Installation  
Instructions for installing ZFDebug

Installation & Usage

To install, place the folder 'ZFDebug' in your library path, next to the Zend folder.

Using the Zend_Application component of Zend Framework 1.8+, add the following method to the Bootstrap class:

protected function _initZFDebug()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('ZFDebug');
    
    $options = array(
        'plugins' => array('Variables', 
                           'File' => array('base_path' => '/path/to/project'),
                           'Memory', 
                           'Time', 
                           'Registry', 
                           'Exception')
    );
    
    # Instantiate the database adapter and setup the plugin.
    # Alternatively just add the plugin like above and rely on the autodiscovery feature.
    if ($this->hasPluginResource('db')) {
        $this->bootstrap('db');
        $db = $this->getPluginResource('db')->getDbAdapter();
        $options['plugins']['Database']['adapter'] = $db;
    }

    # Setup the cache plugin
    if ($this->hasPluginResource('cache')) {
        $this->bootstrap('cache');
        $cache = $this-getPluginResource('cache')->getDbAdapter();
        $options['plugins']['Cache']['backend'] = $cache->getBackend();
    }

    $debug = new ZFDebug_Controller_Plugin_Debug($options);
    
    $this->bootstrap('frontController');
    $frontController = $this->getResource('frontController');
    $frontController->registerPlugin($debug);
}

Using older Zend Framework versions, add the following lines to your bootstrap file:

// Leave 'Database' options empty to rely on Zend_Db_Table default adapter

$options = array(
    // 'jquery_path' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
    'plugins' => array('Variables', 
                       'Html', 
                       'Database' => array('adapter' => array('standard' => $db)), 
                       'File' => array('base_path' => 'path/to/application/root'), 
                       'Memory', 
                       'Time', 
                       'Registry', 
                       'Cache' => array('backend' => $cache->getBackend()), 
                       'Exception')
);

$debug = new ZFDebug_Controller_Plugin_Debug($options);

$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin($debug);

The $options parameter can be either an array or an instance of Zend_Config with the following keys (defaults in paranthesis)

It is possible to set custom timers:

// Get the frontcontroller and the debug bar
$frontController = Zend_Controller_Front::getInstance();
$zfDebug = $frontController->getPlugin('ZFDebug_Controller_Plugin_Debug');

// Set a custom timer
$zfTimer = $zfDebug->getPlugin('Time');
$zfTimer->mark('Query 1');
...
$zfTimer->mark('Query 1');

If mark() is called only once, the time since $_SERVER['REQUEST_TIME'] will be shown. If invoked twice with the same name, the time between the two calls will be shown.

The same is possible with the memory plugin:

$zfMemory = $zfDebug->getPlugin('Memory');
$zfMemory->mark('Query 1');
...
$zfMemory->mark('Query 1');

If mark() is called once, the peak memory usage is shown. Invoked twice, the delta memory usage is printed.


Comment by drakos7, May 08, 2009

Scienta_Controller_Plugin_Debug? should be ZFDebug_Controller_Plugin_Debug? now, right?

Comment by a.alonzi, May 25, 2009

yes

Comment by A.Maho...@gmail.com, Jun 18, 2009

Translation with screen shots, for russian-speaking users - http://zendframework.ru/articles/zfdebug-panel-for-debugging

Comment by greg606, Jul 10, 2009

How to set /path/to/project/ in windows?

Comment by silvan.muhlemann, Jul 15, 2009

Wow! Works like a charm!

@greg606: In my case (using Zend_Application?) I replaced '/path/to/project/' with the constant APPLICATION_PATH

Comment by Themodem, Jul 19, 2009

if ($this-hasPluginResource('db')) {

Should be if ($this->hasPluginResource('db')) {

And

if ($this-hasPluginResource('cache')) {

Should Be

if ($this->hasPluginResource('cache')) {

Comment by greg606, Aug 20, 2009

Silvan, Themodem, Thanks guys.

It really works and gives some nice numbers ;) I can't use them yet but still it may come in handy....

Comment by greg606, Aug 20, 2009

$cache = $this-getPluginResource('cache')->getDbAdapter(); // should be: $cache = $this->getPluginResource('cache')->getDbAdapter();

;)

Comment by f.napoleoni, Aug 31, 2009

I wrote a simple Application Resource in order to load ZFDebug only using application.ini (when using Zend_Application? bootstrap process). Here you can find the code for the resource and this is the configuration in application.ini file:

[development : production]
; enable zfdebug plugin
resources.zfdebug.enabled = true
resources.zfdebug.params.plugins[] = "Variables"
resources.zfdebug.params.plugins.File.base_path = APPLICATION_PATH "/../"
resources.zfdebug.params.plugins[] = "Database"
resources.zfdebug.params.plugins[] = "Memory"
resources.zfdebug.params.plugins[] = "Time"
resources.zfdebug.params.plugins[] = "Registry"
resources.zfdebug.params.plugins[] = "Exception"

Thanks for this plugin, and hope my code will make integration into existing apps simpler.

Bye.

Comment by val.root, Nov 05, 2009
$options = array(
'plugins' => array('Variables',
'File' => array('base_path' => '/path/to/project'),

what should I enter to /path/to/project? application folder?

Comment by maximvassilyev, Nov 25, 2009

Thanks that's very useful


Sign in to add a comment
Hosted by Google Code