一、简介
ZFDebug是一个ZendFramework调试工具条,这个工具条会出现在每个页面的最底部。能够显示页面展示发费时间,内存使用,数据库查询的数量,各变量运行期值,完整的SQL查询语句和查询时间,Zend_Cache和APC的缓存信息,运行异常信息等等。
站点:http://code.google.com/p/zfdebug/
二、安装方法
下载文件之后把ZFDebug\library下的ZFDebug目录 复制到ZF项目的库文件夹下。我的文件目录是这样的
然后把demos下Zend_Application_Bootstrap.php 中的_initZFDebug项目的引导文件Bootstrap.php中。
然后刷新一下网页看一下是否成功。注意一定要开启session会话
三、灵活使用
在实际的使用过程中还要注意下面几点,
在默认的情况下zfdebug只显示三项的调试信息,如果要想显示更多的调试信息类型,就要修改
你项目的Bootstrap.php的_initZFDebug的内容。
例如:
<?php protected function _initZFDebug() { $autoloader = Zend_Loader_Autoloader::getInstance (); $autoloader->registerNamespace ( 'ZFDebug' ); $options = array ('plugins' => array ('Variables', //'File' => array('base_path' => '/path/to/project'), 'File' => array ('base_path' => APPLICATION_PATH.'/../' ), '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 ); // Set a custom timer $zfTimer = $debug->getPlugin('Time'); $zfTimer->mark('Query 1'); } ?>
在默认情况下,zfdebug使用的js文件是http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js,最好修改成本地的,速度快
解决的办法是修改_initZFDebug()的jquery_path变量。
$options = array(
'plugins' => array('Variables',
'Memory',
'Time',
'Registry',
'Exception'),
'jquery_path'=>"http://lcoalhost/zfproject/templates/default/js/jquery.min.js"
);
核心类 ZFDebug_Controller_Plugin_Debug
效果图:
四. 失败解决方法:
1.Make sure your APPLICATION_ENV isset to 'development'.
2.Make sure to have a valid layout (with<head>and<body> etc).
3.The basePath option should be APPLICATION_PATH .'/../'.
参考文档:
http://code.google.com/p/zfdebug/wiki/Installation
http://hi.baidu.com/wuhui/item/0c25c2e5ebefb63c4ddcaf2d
丰富的面板截图: