Example #1
0
 /**
  * {@inheritdoc}
  */
 public function render($params = array())
 {
     $currentViewsDir = $this->view->getViewsDir();
     $this->view->setViewsDir($this->getServiceViewPath());
     $this->view->disableLevel(View::LEVEL_LAYOUT);
     $content = $this->view->getRender('services', $this->templateName, $params);
     //rollback viewsDir
     $this->view->setViewsDir($currentViewsDir);
     return $content;
 }
Example #2
0
 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     //Read configuration
     $config = (include __DIR__ . "/config/config.php");
     // The URL component is used to generate all kind of urls in the application
     $di->set('url', function () use($config) {
         $url = new Url();
         $url->setBaseUri($config->application->baseUri);
         return $url;
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new EventsManager();
         //Attach a listener
         $eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(['module' => 'backend', 'controller' => 'errors', 'action' => 'notFound']);
                         return false;
                 }
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Phanbook\\Backend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => '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;
     });
     $configMenu = (include __DIR__ . "/config/config.menu.php");
     $di->setShared('menuStruct', function () use($configMenu) {
         // if structure received from db table instead getting from $config
         // we need to store it to cache for reducing db connections
         $struct = $configMenu->get('menuStruct')->toArray();
         return $struct;
     });
 }
Example #3
0
 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     //$config = include __DIR__ . "/config/config.php";
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $eventsManager = new EventsManager();
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             $object = $event->getData();
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(['controller' => 'errors', 'action' => 'index']);
                         return false;
                     case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
                         $dispatcher->forward(['controller' => 'errors', 'action' => 'show404']);
                         return false;
                 }
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Phanbook\\Frontend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($di) {
         $config = $di->get('config');
         $view = new View();
         $view->setViewsDir(ROOT_DIR . 'content/themes/' . $config->theme);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => 'volt']);
         // Create an event manager
         $eventsManager = new EventsManager();
         $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;
     });
 }
Example #4
0
 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => 'volt']);
         // Create an event manager
         $eventsManager = new EventsManager();
         $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;
     });
 }
Example #5
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     // The URL component is used to generate all kind of urls in the application
     $di->set('url', function () {
         $url = new Url();
         $url->setBaseUri('/');
         return $url;
     });
     /**
      * 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]);
         $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' => true]);
             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;
     });
 }
Example #6
0
 /**
  * Register the services here to make them general
  * or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(DiInterface $di)
 {
     //Read configuration
     $config = (include __DIR__ . "/config/config.php");
     $configGlobal = $di->getConfig();
     $di->set('url', function () use($config, $configGlobal) {
         $url = new Url();
         if (APPLICATION_ENV == 'production') {
             $url->setStaticBaseUri($configGlobal->application->production->staticBaseUri);
         } else {
             $url->setStaticBaseUri($configGlobal->application->development->staticBaseUri);
         }
         $url->setBaseUri($config->application->baseUri);
         return $url;
     });
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $eventsManager = $this->getEventsManager();
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 $message = $exception->getMessage();
                 $response = $this->getResponse();
                 switch ($exception->getCode()) {
                     case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                         $response->redirect();
                         return false;
                     case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $response->redirect('action-not-found?msg=' . $message);
                         return false;
                     case Dispatcher::EXCEPTION_CYCLIC_ROUTING:
                         $response->redirect('cyclic-routing?msg=' . $message);
                         return false;
                 }
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Phanbook\\Frontend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($di) {
         $config = $di->get('config');
         $view = new View();
         $view->setViewsDir(ROOT_DIR . 'content/themes/' . $config->theme);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => 'volt']);
         // Create an event manager
         $eventsManager = $this->getEventsManager();
         $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;
     });
 }
Example #7
0
 protected function _getViewDisabled($level = null)
 {
     $view = new Phalcon\Mvc\View();
     $view->setViewsDir('unit-tests/views/');
     $view->setTemplateAfter('after');
     $view->setTemplateBefore('before');
     if ($level !== null) {
         $view->disableLevel($level);
     }
     $view->start();
     $view->render('test13', 'index');
     $view->finish();
     return $view;
 }
Example #8
0
 protected function view()
 {
     $config = $this->_config;
     $this->_di->set('view', function () use($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]);
             return $volt;
         }]);
         return $view;
     });
 }
Example #9
0
     $volt->setOptions(array("compiledPath" => COMPILED_VIEW_PATH, "compiledExtension" => ".php"));
     return $volt;
 });
 $di->set('crypt', function () {
     $crypt = new Crypt();
     // 使用 blowfish
     $crypt->setCipher('blowfish');
     // 设置全局加密密钥
     $crypt->setKey('blowfish');
     return $crypt;
 }, true);
 // Setting up the view component
 $di['view'] = function () {
     $view = new View();
     $view->setViewsDir('../app/views/');
     $view->disableLevel(array(View::LEVEL_LAYOUT => true, View::LEVEL_MAIN_LAYOUT => true));
     $view->registerEngines(array(".phtml" => 'voltService', ".volt" => 'voltService', ".json" => 'voltService'));
     return $view;
 };
 // Setup a base URI so that all generated URIs include the "tutorial" folder
 $di['url'] = function () {
     $url = new Url();
     $url->setBaseUri("/cgi/");
     return $url;
 };
 // Setup the tag helpers
 $di['tag'] = function () {
     return new Tag();
 };
 // add routing capabilities
 $di->set('router', function () {
Example #10
0
$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' => '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
    $view->setEventsManager($eventsManager);
    return $view;
});
// Register the flash service with custom CSS classes
$di->set('flashSession', function () {
    $flash = new Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning']);
    return $flash;
Example #11
0
 protected function _getViewDisabled($level = null)
 {
     $view = new View();
     $view->setViewsDir(PATH_DATA . "views" . DIRECTORY_SEPARATOR);
     $view->setTemplateAfter("after");
     $view->setTemplateBefore("before");
     if ($level !== null) {
         $view->disableLevel($level);
     }
     $view->start();
     $view->render("test13", "index");
     $view->finish();
     return $view;
 }