首页 > php, zend framework > Zend Framework 调试插件

Zend Framework 调试插件

2010年8月1日 effect 发表评论 阅读评论

做了一个ZF调试的插件,这个插件就简单的把一些变量打印出来,希望能帮到大家。

先看一下效果:

增加步骤
1. 新建一个php脚本,内容如下:(我保存在php的include_path里面的Plugin的debug.php)

<?php
require_once 'Zend/Controller/Plugin/Abstract.php';
class My_Plugin_Debug extends Zend_Controller_Plugin_Abstract {
    private $startTime = 0;
    private $endTime = 0;
    private function getsection(){
        list($msec, $sec) = explode(" ", microtime());
        return $sec+$msec;
    }
    public function routeStartup(Zend_Controller_Request_Abstract $resquest){
        $this->startTime = $this->getsection();
    }
    public function postDispatch(Zend_Controller_Request_Abstract $request){
        $response = $this->getResponse();
        $this->endTime = $this->getsection();
 
        $startTime = $this->startTime;
        $endTime =$this->endTime;
        $allTime =($this->endTime - $this->startTime);
 
        $moduleName = $request->getModuleName();
        $controllerName = $request->getControllerName();
        $actionName = $request->getActionName();
        $view_path = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
        $viewFile =$view_path->getViewScript();
 
        $params = Zend_Debug::dump($request->getParams(),null,false);
        $view = $view_path->view;
        $vars = $view->getVars();
        $viewVars =Zend_Debug::dump($vars,null,false);
 
        $str = <<<DEBUG
        <style>
        table.debug__ {background-color:#888}
        .debug__ td{background-color:#fff;padding:5px 9px;}
        </style>
        <table border="0" cellpadding="1" cellspacing="1" class="debug__">
        <tr><td colspan="2" align="center">调试信息</td></tr>
        <tr><td>开始时间</td><td>{$startTime}</td></tr>
        <tr><td>结束时间</td><td>{$endTime}</td></tr>
        <tr><td>花费时间</td><td>{$allTime}</td></tr>
        <tr><td>使用模块</td><td>{$moduleName}</td></tr>
        <tr><td>控制器</td><td>{$controllerName}</td></tr>
        <tr><td>方法</td><td>{$actionName}</td></tr>
        <tr><td>视图文件</td><td>{$viewFile}</td></tr>
        <tr><td>请求参数</td><td>{$params}</td></tr>
        <tr><td>视图变量</td><td>{$viewVars}</td></tr>
        </table>
DEBUG;
        $response->appendBody($str);
    }
}
?>

2。在你的入口文件增加以下代码:要在Font->dispatch();之前

require_once ‘Plugin/debug.php’; //这里就是你刚才新建的php脚本。以你的实际情况载入
$font->registerPlugin(new My_Plugin_Debug(), 9999999);

这样就OK了。

还需要改进的是加入DB的调试信息。

有问题欢迎提出哈

注意:本文为原创,转载请注明出处,多谢!

分类: php, zend framework 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.