Debug variables in Yii 2

AUTHOR: dang.nh


I’ve been working with Yii framework version 2.0 for a few days now, and I find Yii’s Debugger and vardumper function are extremely uncomfortable!

Since for the sake of Simplicity and Quick Development, I’ve created a helper for those who use Yii. You can just call dd($var1, $var2, ….); for dump & die or d($var1, $var2, ….); for dump data.

p/s: Please scroll to the end of this article for sample result.

p/s 2: Those functions work with all PHP version

Installation:

  • Create a file so called functions.php in

/common/config/

2

  • Paste those code into function.php then save it

  • Now, edit bootstrap.php in

/common/config/bootstrap.php

3

and then add this line of code to the top:

like so

4

Voila! Now you can call d($var1, $var2, $varx); for dump or dd($var1, $var2, $varx) for dump then die anywhere in your application!

Sample result:

Post Views: 133

Comments

comments