当前位置: 首页>>代码示例>>PHP>>正文


PHP DiInterface::getResponse方法代码示例

本文整理汇总了PHP中Phalcon\DiInterface::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::getResponse方法的具体用法?PHP DiInterface::getResponse怎么用?PHP DiInterface::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\DiInterface的用法示例。


在下文中一共展示了DiInterface::getResponse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: registerServices

 /**
  * 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();
     // The URL component is used to generate all kind of urls in the application
     $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 () use($di) {
         //Create/Get an EventManager
         $eventsManager = new EventsManager();
         //Attach a listener
         $eventsManager->attach('dispatch', function ($event, $dispatcher, $exception) use($di) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 $message = $exception->getMessage();
                 $response = $di->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\\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;
     });
 }
开发者ID:SidRoberts,项目名称:phanbook,代码行数:76,代码来源:Module.php


注:本文中的Phalcon\DiInterface::getResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。