/** * Render template. * * @param string $template Template name. * @param array $params Template params. * * @return string */ private function _viewRender($template, $params) { ob_start(); $viewsDir = $this->_view->getViewsDir(); $this->_view->setViewsDir(ROOT_PATH . '/app/modules/Core/View'); $this->_view->partial('Profiler/' . $template, $params); $this->_view->setViewsDir($viewsDir); $html = ob_get_contents(); ob_end_clean(); return $html; }
// Set the views cache service $di->set('viewCache', function () use($di) { $config = $di->get('config'); if ($config->application->debug) { return new MemoryBackend(new FrontendNone()); } else { // Cache data for one day by default $frontCache = new FrontendOutput(['lifetime' => $config->cache->lifetime]); return new FileCache($frontCache, ['cacheDir' => $config->cache->cacheDir, 'prefix' => $config->cache->prefix]); } }); // Setting up the view component $di->set('view', function () use($di, $eventsManager) { $config = $di->get('config'); $view = new View($config->toArray()); $view->setViewsDir($config->application->view->viewsDir); $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]); $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->addExtension(new \Phanbook\Tools\VoltFunctions()); return $volt; }]); // 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