极湖

无不用其“极”

Subscribe to RSS feed

Posts tagged with "Debug"

ZFDebug - Zend Framework 的调试工具

,

Zend Framework 进行开发,如果要查看所执行的 SQL 等信息,需要自己写一些代码才能实现。

现在有一个叫 ZFDebug 的东西,实现了调试过程的标准化,个人感觉这东西挺不赖,因此推荐一下。

安装过程很简单:

1. ZFDebug 文件夹拷贝到和 Zend 同级目录下面。
2. 在 Bootstrap.php 中追加代码:
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);
}


注意以上代码仅适用于 ZF 1.8 以上版本。

Smarty 下最简单的调试方法

, ,

很简单的一句话,却常常忘记,因此记录一下:
{$var|@debug_print_var}

稍微复杂一点的用法:
{$var|@debug_print_var:2:100}

意思是缩进长度为2个空格,每行最多字数为100。

其他调试方法可以参考这个(日文)
February 2012
S M T W T F S
January 2012March 2012
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29