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');
// // 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的控制台信息中:
如果将配置文件中的ShowInFirebug设置为False,便会打印在当前页面的底部。
参考链接:http://jianshu.io/p/1Exyox