当前位置:Gxlcms > PHP教程 > yii如何使用CWebLogRoute记录和调试变量routedeleterouteadddefaultgwlinuxroutead

yii如何使用CWebLogRoute记录和调试变量routedeleterouteadddefaultgwlinuxroutead

时间:2021-07-01 10:21:17 帮助过:12人阅读

简介

我看了几遍关于使用外部库来调试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教程有兴趣的朋友有所帮助。

  • 人气教程排行