Yii 1.1: kint

Display the contents of vars in a readable way.
19 followers

Kint is a simple tool that presents the contents of a variable in a readable way. It's an alternative to var_dump() or scripts like Krumo.

You can find more information on the site of the original class.

screenshot

Requirements

Tested on 1.1.8. Should work on earlier versions.

Setup

  • Download and extract the folder under protected/extensions.
  • Add to your config (main.php) under components:
'kint' => array(
    'class' => 'ext.Kint.Kint',
),

Add it to your preload property (this is only for declaring the shortcut functions):

'preload' => array('log', 'kint'),

Note: You can still use the plugin without autoloading, but instead of using the shortcut functions, you have to use:

Kint::dump($variable);

Usage

To dump a variable:

d($variable);

There is often a need to halt execution after dumping a particular variable:

dd($variable); // execution will stop after this statement; same as d($variable);die;

To print out variable information in simple text (no CSS style or javascript) use

s($variable); // stands for "simple"
    // or, as before
  sd($variable); // this will halt execution after displaying data

There are also (currently two) modifiers:

+d($variable); // will dump variable information without limiting the depth
    /// and
  -d($variable); // will run ob_clean() beforehand, so this dump is at the top
                   // of the page. Best used with dd().

The latter are possible because the class analyzes the PHP code itself where it was called from.

Last, but not least, you can output a pretty and readable backtrace:

Kint::trace();

Total 3 comments

#14932 report it
ineersa at 2013/09/23 05:56am
Added repo on github and some functionality.

Hello wisp. Since you didnt mentioned any code repository, and i didnt found any, i decide to make one on github.

As for functionality, the only thing i missed was wrapping var_dump to html comments. I made some changes (maybe not so nice) to parse !d to reach what i need.

Code can be found here - https://github.com/ineersa/kint.

#6410 report it
wisp at 2012/01/08 09:28am
preload

Hi pligor, normally you call an extension like Kint::dump(); and the file is automatically imported but when you want to use a shortcut function it has to be declared in advance, that's why I used the preload property. It does nothing more than declare a couple of functions, so it shouldn't have any noticeable impact on performance. (and you can also disable it on production)

If you don't mind typing Kint::dump($var); everytime you need to debug a var, you could simply leave out the preload property.

Placing it in external folder is a good way, but of course the code I provided is only to get people started :)

#6393 report it
pligor at 2012/01/06 06:16pm
no need to preload

Do you think preload is necessary? I just included the line

'ext.Kint.Kint',

inside the 'import' array for autoloading and it works fine (:

Well in fact for all my downloaded extensions, or generally code not developed by me, I use another directory outside of the current project and for this folder I have set the alias 'external' So in my case you will see:

'external.Kint.Kint',

If you think that preload improves perfomance please let me know (:

Leave a comment

Please to leave your comment.

Create extension
Downloads