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

Problems with the Volt and controller

What function you want to call? Can you add some code?

What function you want to call? Can you add some code?

forgot)) ddiff()

In your service file where you define Volt:

// View
$di->setShared('view', function() use ($di) {
    $view = new \Phalcon\Mvc\View();
    ...
    ...
    $view->registerEngines([
        '.phtml' => function($view, $di) {
            $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

            ...
            ...

            // Extended functions
            $compiler->addFunction('ddiff', function($resolvedArgs, $exprArgs){
                return 'Vokuro\Controllers\IndexController::ddiff(' . $resolvedArgs . ')';
            });
            return $volt;
        }
    ]);
    return $view;
});

In your controller, make the ddiff function static:

public static function ddiff()

In your Volt file:

{{ ddiff() }}

But you should move the ddiff function in external file, be it library or helper. It does not belong in the controller.

edited Apr '18

Sorry I can't understand what should be instead of points.

And error with var $compiler:

Notice: Undefined variable: compiler in /home/amanskiy/web/work.revolution-games.ru/public_html/app/config/services.php on line 207

Fatal error: Uncaught Error: Call to a member function addFunction() on null in /home/amanskiy/web/work.revolution-games.ru/public_html/app/config/services.php:207 Stack trace: #0 [internal function]: Closure->{closure}(Object(Phalcon\Mvc\View), Object(Phalcon\Di\FactoryDefault)) #1 [internal function]: Phalcon\Mvc\View->_loadTemplateEngines() #2 [internal function]: Phalcon\Mvc\View->render('index', 'index') #3 /home/amanskiy/web/work.revolution-games.ru/public_html/public/index.php(42): Phalcon\Mvc\Application->handle() #4 {main} thrown in /home/amanskiy/web/work.revolution-games.ru/public_html/app/config/services.php on line 207

... means there is other code that is not important to the problem. Can you paste your Volt service definition so i can show you where to put it?