We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Improve dump() with kint - debugging helper

I want to advise me how I can add a function Kint() for Volt. This tool is visually me useful when debugging. Help me please. https://raveren.github.io/kint/



58.3k

Hello

You just include it into your service file, take look example https://github.com/phanbook/phanbook/blob/master/core/config/services.php#L452



40.0k
Accepted
answer

I add function to compiler:

$view->registerEngines([
        '.volt' => function ($view, $di) {
            $config = $this->getConfig();

            $volt = new VoltEngine($view, $di);

            $volt->setOptions([
                'compiledPath' => $config->application->cacheDir,
                'compileAlways' => $config->dev_environment,
                'stat' => $config->dev_environment,
                'compiledSeparator' => '_'
            ]);

            $compiler = $volt->getCompiler();

            if ($config->dev_environment){

                $compiler->addFunction(
                    'kint',
                    function ($resolvedArgs, $exprArgs) {
                        return 'd('.$resolvedArgs.')';     // <-- kint function
                    }
                );
            }

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ]);

in index.php

/**
* Debug
*/
        if($app->config->dev_environment){
            //require '../vendor/raveren/kint/Kint.class.php';
            Kint::$theme = 'solarized';

            $debug = new \Phalcon\Debug();
            $debug->listen();
        }

composer:

{

  "require": {
  },

  "require-dev": {
    "raveren/kint": "*"
  }

}

Work fine.

edited Sep '16

Now, this is useful!

Volt can have odd behaviour sometimes.

P.S. you cannot use both native Phalcon Debug component and Kint tool. You have to disable Kint in order to use Phalcon Debug and vice versa.

kint() == var_dump()

I will find out about the use of debug Phalcon.

But so far I have had no problem using the two, since kint is a var_dump ()

kint() == var_dump()

That is quite not true. Kint is much more than var_dump. Better than xdebug or similiar.