Esempio n. 1
0
 /**
  * Initializes Volt engine
  */
 public function register()
 {
     $di = $this->getDi();
     $eventsManager = $this->getEventsManager();
     $config = $this->_config;
     $moduleDirectory = $this->_module->getModuleDirectory();
     $defaultModuleDir = $this->_module->getDefaultModuleDirectory();
     $di->set('view', function () use($di, $moduleDirectory, $defaultModuleDir, $eventsManager, $config) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($moduleDirectory . '/View/');
         $view->setLayoutsDir($defaultModuleDir . '/View/layouts/');
         $view->registerEngines([".volt" => 'viewEngine']);
         // Attach a listener for type "view"
         if (!$config->application->debug) {
             $eventsManager->attach("view", function ($event, $view) use($di) {
                 if ($event->getType() == 'notFoundView') {
                     $di->get('logger')->error('View not found - "' . $view->getActiveRenderPath() . '"');
                 }
             });
             $view->setEventsManager($eventsManager);
         } elseif ($config->application->profiler) {
             $eventsManager->attach("view", function ($event, $view) use($di) {
                 if ($di->has('profiler')) {
                     if ($event->getType() == 'beforeRender') {
                         $di->get('profiler')->start();
                     }
                     if ($event->getType() == 'afterRender') {
                         $di->get('profiler')->stop($view->getActiveRenderPath(), 'view');
                     }
                 }
                 if ($event->getType() == 'notFoundView') {
                     $di->get('logger')->error('View not found - "' . $view->getActiveRenderPath() . '"');
                 }
             });
             $view->setEventsManager($eventsManager);
         }
         return $view;
     });
 }
Esempio n. 2
0
 public function setView($viewPath = '../app/views/', $volt)
 {
     $di = $this->getDI();
     $di->set('view', function () use($viewPath, $volt) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir($viewPath);
         if ($volt) {
             /*
                             $view->registerEngines(
                                 array(
                                     ".volt" => 'Phalcon\Mvc\View\Engine\Volt'
                                 )
                             );*/
             $view->registerEngines(array('.volt' => function ($view, $di) {
                 $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
                 $volt->setOptions(array('compiledPath' => "../app/cache/", 'compiledSeparator' => '_'));
                 return $volt;
             }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         }
         if ($this->_debug) {
             //	Track Views
             $eventsManager = new \Phalcon\Events\Manager();
             $eventsManager->attach("view", function ($event, $view) {
                 if ($event->getType() == 'beforeRenderView') {
                     $this->_views[] = $view->getActiveRenderPath();
                 }
             });
             $view->setEventsManager($eventsManager);
         }
         return $view;
     });
     $this->setDI($di);
 }