How to disable DUMP function in Volt template

Hi Phalcon pro,

My web application allows users edit files view use systax Volt template with extension .phtml

In Controller: I try to use the command $this->view->model = ModelTest::find (); And in View, i try {{ dump(model) }}

It displays the database information and the important things in the application. How to limit those that are?

'database' => array(
        'adapter' => 'Mysql',
        'host' => 'localhost',
        'username' => 'root',
        'password' => '',
        'dbname' => 'cmsphalcon',
        'charset' => 'utf8'
    ),

You may be able to remove the dump function from Volt, by extending the engine. Either by replacing the existing function with empty space or something else

$compiler->addFunction('dump', '');

or on compiling to return empty. Check the documentation below. It shows you examples how to do either way.

https://docs.phalconphp.com/en/latest/reference/volt.html#extending-volt

Hi Stefan Chiriac, Errors occur when using this command

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

$compiler = $volt->getCompiler();
$compiler->addFunction('dump', '');

$volt->setOptions(array(
    'compiledPath' => $config->application->cacheDir,
    'compiledSeparator' => '_'
));

return $volt;

Catchable fatal error: Object of class Phalcon\Mvc\Model\Resultset\Simple could not be converted to string

I want to replace it with null values when using the dump command in Volt template

edited Apr '16

addFunction expects a function, so I guess an Empty string won't work. You can try null, or create an annonymous function

    $compiler->addFunction(
        'dump',
        function ($resolvedArgs, $exprArgs) {
            return '';
        }
    );

Other way use an extension

    class PhpFunctionExtension
    {
        /**
         * This method is called on any attempt to compile a function call
         */
        public function resolveExpression($name, $arguments)
        {
            if (function_exists($name) && $name == 'dump') {
                return '';
            }
        }
    }

    // Register the extension in the compiler
    $compiler->addExtension(new PhpFunctionExtension());

https://docs.phalconphp.com/en/latest/reference/volt.html#extensions

I'm not home to try it, so give it a try. But is something around this. Check the docs for more about this subject

it does not work, please help me

$compiler->addExtension(new \App\Vendor\Fdola\VoltExtension());
namespace App\Vendor\Fdola;

class VoltExtension {
    public function resolveExpression($name, $arguments) {
        if (function_exists($name) && $name == 'dump') {
            return '';
        }
    }
}