I have read several times about using external libraries to Debug PHP code (for example, firePHP). after reading this article, you will find that these external libraries are not necessary in Yii.
I have read several times about using external libraries to Debug PHP code (such as firePHP). after reading this article, you will find that these external libraries are not necessary in Yii.
Yii has a built-in powerful logging class. if you read the log recording document, you can find that we can decide the log we want to record. this is exactly what we want to do. use CWebLogRoute to create a Yii version of FirePHP.
Configuration
Add the configuration in our protected/config/main. php configuration file:
'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 ), ),
Use
After the preparation is complete, let's track the variables and test them as follows:
$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'); // arrayecho Yii::trace(CVarDumper::dumpAsString($anotherTest),'vardump'); // objectecho Yii::trace(CVarDumper::dumpAsString($this),'vardump');
FirePHP functions of Yii
The above code has been written for a long time. let's use some strong suggestions and let me write a function like FirePHP on the index. php page:
//// In your index.php or your globals.php filefunction fb($what){ echo Yii::trace(CVarDumper::dumpAsString($what),'vardump');} // // using the above examples now we could$test = 'This is a test'; fb($test);
Okay, all done. we didn't use external classes in the debugger.
Supplement
I forgot to mention it. it also applies to the Chrome development tool console.
How to log and debug variables using CWebLogRoute