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.