yii 如何使用 CWebLogRoute 记录和调试变量 route delete route add default gw linux route ad

原创
2016-07-29 08:48:34972浏览

简介

我看了几遍关于使用外部库来调试PHP代码(如: firePHP)的文章, 读了这篇文章你会发现在 Yii 中没有必要使用这些外部库.
Yii 内置了强大的日志记录类. 如果你阅读了记录日志的文档, 你可以发现我们可以决定我们希望记录的日志, 这正是我们要做的,使用 CWebLogRoute 创建一个 Yii 版本的 FirePHP.

配置

在我们的 protected/config/main.php 配置文件中添加配置:

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
        array(
            'class'=>'CWebLogRoute',
            //// I include *trace* for the// sake of the example, you can include//// more levels separated by commas'levels'=>'trace', 
            //// I include *vardump* but you// can include more separated by commas'categories'=>'application.*,system.db.*,vardump', 
            //// This is self-explanatory right?'showInFireBug'=>true ), 
        ),
),

使用

准备完毕,现在让我们来追踪一下变量来测试一下, 如下:

publicfunctionactionTrace(){$test = 'This is a test';

    $anotherTest = array('one','two','three');

    echo Yii::trace(CVarDumper::dumpAsString($test),'vardump');

    echo Yii::trace(CVarDumper::dumpAsString($anotherTest),'vardump');

    echo Yii::trace(CVarDumper::dumpAsString($this),'vardump');
}

Yii 的 FirePHP 函数

上面的代码写起来比较长, 我们来使用一下 强的建议, 让我在 index.php 页面写一个像 FirePHP 函数:

publicfunctionactionTrace()
{//// In your index.php or your globals.php filefunctionfb($what)
    {echo Yii::trace(CVarDumper::dumpAsString($what), 'vardump');
    }

    // // using the above examples now we could$test = 'This is a test';

    fb($test);
}

OK, 全部完成了,我们的调试器中没有使用外部的类.

补充

此方法无需安装chromephp 插件,firebug浏览器均可使用,opera,chrome,firefox等都适用。

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了yii 如何使用 CWebLogRoute 记录和调试变量,包括了route,eblog方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。