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'=>'vardump', // // This is self-explanatory right? 'showInFireBug'=>true ), ),
准备完毕,现在让我们来追踪一下变量来测试一下, 如下:
$test = 'This is a test';
$anotherTest = array('one','two','three');
// variable
// please, check the inclusion of the category *vardump*
// not including the category, it wont display at all.
echo Yii::trace(CVarDumper::dumpAsString($test),'vardump');
// array
echo Yii::trace(CVarDumper::dumpAsString($anotherTest),'vardump');
// object
echo Yii::trace(CVarDumper::dumpAsString($this),'vardump');
上面的代码写起来比较长, 我们来使用一下 强的建议, 让我在 index.php 页面写一个像 FirePHP 函数:
// // In your index.php or your globals.php file function fb($what){ echo Yii::trace(CVarDumper::dumpAsString($what),'vardump'); } // // using the above examples now we could $test = 'This is a test'; fb($test);
OK, 全部完成了,我们的调试器中没有使用外部的类.
注意:按照以上配置生成的Log日志内容将会被使用在Firebug或者chrome的控制台信息中:
转载于:https://blog.51cto.com/webcrawler/1212417