Hey man
You can adding function of php via view, for example
// Setting up the view component
$di->set(
'view',
function () use ($config) {
$view = new View();
$view->setViewsDir($config->application->view->viewsDir);
$view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
//@TODO: move to an extensions/filters/functions file.
$view->registerEngines(
[
'.volt' => function () use ($view, $config) {
$volt = new Volt($view);
$volt->setOptions(
[
'compiledPath' => $config->application->view->compiledPath,
'compiledSeparator' => $config->application->view->compiledSeparator,
'compiledExtension' => $config->application->view->compiledExtension,
'compileAlways' => $config->application->debug,
]
);
$compiler = $volt->getCompiler();
$compiler->addFunction(
't',
function ($string) {
return t($string);
}
);
$compiler->addFunction('array_key_exists', 'array_key_exists');
$compiler->addFilter(
'truncate',
function ($str, $maxLen = 35, $suffix = '...') {
return 'Hovercrowd\Models\Tools::truncate(' . $str . ')';
}
);
return $volt;
}
]
);
// Create an event manager
$eventsManager = new EventsManager();
// Attach a listener for type 'view'
$eventsManager->attach(
'view',
function ($event, $view) {
if ($event->getType() == 'notFoundView') {
throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
}
}
);
// Bind the eventsManager to the view component
$view->setEventsManager($eventsManager);
return $view;
}
);