如何在Yii中转储和打印变量以进行调试?我想使用var_dump()或print_r().我试图使用Yii :: trace()但它在runtime / logs / app.log中崩溃了这个错误.它甚至没有告诉我代码中的行失败.
2015-03-18 20:54:11 [::1][-][-][warning][yii\log\Dispatcher::dispatch] Unable to send log via yii\debug\LogTarget: Exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.PHP:58 Stack trace: #0 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.PHP(58): serialize(Array) #1 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.PHP(112): yii\debug\LogTarget->export(Array) #2 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2/log/Dispatcher.PHP(183): yii\debug\LogTarget->collect(Array,true) #3 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2/log/Logger.PHP(170): yii\log\Dispatcher->dispatch(Array,true) #4 [internal function]: yii\log\Logger->flush(true) #5 {main}
参考
http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html
因为你问的是像var_dump和print_r这样的东西,我可以为此建议内置帮助器.它被称为
yii\helpers\VarDumper.
Yii::trace()用于记录跟踪消息.
VarDumper is intended to replace the buggy PHP function
var_dump
andprint_r
.It can correctly identify the recursively referenced objects in a
complex object structure. It also has a recursive depth control to
avoid indefinite recursive display of some peculiar variables.VarDumper can be used as follows,
VarDumper::dump($var);
就个人而言,我不使用它,只是尝试了几次进行测试.
我认为最好将Xdebug用于此目的.
另见PsySH.