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


PHP Mvc\Dispatcher类代码示例

本文整理汇总了PHP中Phalcon\Mvc\Dispatcher的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher类的具体用法?PHP Dispatcher怎么用?PHP Dispatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: registerServices

 public function registerServices(DiInterface $di)
 {
     $di['dispatcher'] = function () {
         $eventsManager = new \Phalcon\Events\Manager();
         //Attach a listener
         $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
                 return false;
             }
             switch ($exception->getCode()) {
                 case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(array('controller' => 'error', 'action' => 'error404'));
                     return false;
             }
         });
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Frontend\\Controllers");
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     };
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layout_frontend/');
         return $view;
     };
 }
开发者ID:OwLoop,项目名称:Fresh,代码行数:30,代码来源:Module.php

示例2: registerServices

 /**
  * Register specific services for the module
  */
 public function registerServices(DiInterface $di)
 {
     $config = $di->get('config');
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers");
         return $dispatcher;
     });
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) {
             $volt = new VoltEngine($view, $di);
             $config = $di->get('config');
             $volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
     $di->set('aws_s3', function () use($config) {
         //version 2.7 style
         $s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01'));
         return $s3;
     });
 }
开发者ID:corzoit,项目名称:phalcon-boilerplate,代码行数:29,代码来源:Module.php

示例3: registerServices

 /**
  * Register specific services for the module
  */
 function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     });
     $config = $di->getShared('config');
     $di->set('view', function () use($config, $di) {
         $view = new View();
         $router = $di->getShared('router');
         /*
          * @todo 给layouts等目录统一变量
          * */
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('/../../../layouts/');
         // 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
         $view->setLayout('index');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     }, true);
 }
开发者ID:justforleo,项目名称:phalcon-cmf,代码行数:30,代码来源:Module.php

示例4: beforeExecuteRoute

 /**
  * @param Dispatcher $dispatcher
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     // This confirm a private zone
     //check for a closed controller and Action is exist a current session
     if ($this->acl->isClosed($controllerName, $actionName)) {
         if (!is_null($this->auth->getAccess())) {
             //This redirect to another Controller/Action
             $this->response->redirect('dashboard');
             // Disable the view to avoid rendering
             $this->view->disable();
         }
         return true;
     }
     if ($this->acl->isPrivate($controllerName)) {
         if (!is_null($this->auth->getAccess())) {
             //echo "Logeado";
         } else {
             //Display a error by a flash component
             $this->flash->notice('Upss! Access denied, Please Registry first or Login into Kangoo');
             //Execute the dispatcher to move above the user
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
     }
 }
开发者ID:Pablo251,项目名称:Kangoo,代码行数:30,代码来源:ControllerBase.php

示例5: beforeDispatch

 /**
  * This action is executed before execute any action in the application.
  *
  * @param PhalconEvent $event      Event object.
  * @param Dispatcher   $dispatcher Dispatcher object.
  *
  * @return mixed
  */
 public function beforeDispatch(PhEvent $event, Dispatcher $dispatcher)
 {
     $di = $this->getDI();
     $cookie = $di->getCookie();
     $session = $di->getSession();
     $config = $di->getConfig();
     $languageCode = '';
     if ($di->get('app')->isConsole()) {
         return;
     }
     // Detect language from cookie
     if ($cookie->has('languageCode')) {
         $languageCode = $cookie->get('languageCode')->getValue();
     } else {
         // Get default language from language model
         $languageCode = LanguageModel::findFirst(['default = :isdefault: AND status = :enable:', 'bind' => ['isdefault' => LanguageModel::IS_DEFAULT, 'enable' => LanguageModel::STATUS_ENABLE]])->code;
     }
     // Set language code to session
     if ($session->has('languageCode') && $session->get('languageCode') != $languageCode || !$session->has('languageCode')) {
         $session->set('languageCode', $languageCode);
     }
     $messages = [];
     $directory = $di->get('registry')->directories->modules . ucfirst($dispatcher->getModuleName()) . '/Lang/' . $languageCode . '/' . strtolower($dispatcher->getControllerName());
     $extension = '.php';
     if (file_exists($directory . $extension)) {
         require $directory . $extension;
     }
     // add default core lang package
     require $di->get('registry')->directories->modules . self::DEFAULT_LANG_PACK . '/Lang/' . $languageCode . '/default.php';
     $translate = new PhTranslateArray(['content' => array_merge($messages, $default)]);
     $di->set('lang', $translate);
     return !$event->isStopped();
 }
开发者ID:nguyenducduy,项目名称:haraapp,代码行数:41,代码来源:Translate.php

示例6: registerServices

 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $di['dispatcher'] = function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Modules\\Backend\\Controllers");
         return $dispatcher;
     };
     /**
      * Setting up the view component
      */
     $di['view'] = function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('../../common/layouts/backend/');
         $view->setTemplateAfter('main');
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new MySQLAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name));
     };
 }
开发者ID:hoangnghia,项目名称:it102,代码行数:28,代码来源:Module.php

示例7: registerServices

 public function registerServices(\Phalcon\DiInterface $di = null)
 {
     /**
      * Read configuration
      */
     $config = (include dirname(dirname(dirname(__DIR__))) . "/apps/config/config.php");
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     }, true);
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, 'charset' => 'utf8'));
     };
 }
开发者ID:EdgarSM91,项目名称:phalcon-angular,代码行数:28,代码来源:Module.php

示例8: beforeExecuteRoute

    public function beforeExecuteRoute(Event $event,Dispatcher $dispatcher){
        //return;
        //$this->session->destroy();

        $role=$this->session->get('role');
        if(!$role){
            $role=self::GUEST;
        }

        //Get the current Controller & Action from the dispatcher
        $controller=$dispatcher->getControllerName();
        $action=$dispatcher->getActionName();

        //Get the ACL rule list
        $acl=$this->_getAcl();

        //See if they have permission
        $allowed=$acl->isAllowed($role, $controller,$action);
        if($allowed!=Acl::ALLOW){
            $this->flash->error('You Don\'t Have Permission To Access This Area');
            $this->response->redirect('index');

            //Stops the dispatcher at current operation
            return false;
        }
    }
开发者ID:AhmadAborob,项目名称:Phalcon-First-Project,代码行数:26,代码来源:Permission.php

示例9: afterDispatchLoop

 public function afterDispatchLoop(Event $event, Dispatcher $dispatcher)
 {
     $di = $this->getDI();
     $response = $di->get('response');
     $content = $response->getContent();
     if ($content === '' && $dispatcher->getActiveController() instanceof RestControllerInterface) {
         $returnedResponse = $dispatcher->getReturnedValue() instanceof ResponseInterface;
         if ($returnedResponse === false) {
             /** @var \PhalconRest\Mvc\RestView $rest */
             $rest = $di->get('rest');
             /** @var Manager $eventsManager */
             $eventsManager = $this->_eventsManager;
             //$eventsManager = $dispatcher->getDI()->get('eventsManager');
             $renderStatus = true;
             if ($eventsManager instanceof ManagerInterface) {
                 $renderStatus = $eventsManager->fire('application:viewRender', $this, $rest);
             }
             if ($renderStatus) {
                 $rest->render($dispatcher->getControllerName(), $dispatcher->getActionName());
                 $content = $rest->getContent();
             }
             /** @var \Phalcon\Http\Response $response */
             $response = $di->get('response');
             $response->setContent($content)->send();
         }
     }
 }
开发者ID:serebro,项目名称:phalcon-rest,代码行数:27,代码来源:DispatcherEventsHandler.php

示例10: beforeDispatch

 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     if ($this->config->application->user_login_form_cookies) {
         //use cookies
         $auth = $this->_getCookie('auth');
         if (!$auth) {
             $role = 'Guests';
         } else {
             $role = $this->_getCookie('role');
             $role = 'Person';
         }
     } else {
         $auth = $this->session->get('auth');
         $auth = $this->_getCookie('auth');
         if (!$auth) {
             $role = 'Guests';
         } else {
             $role = $auth['role'];
             // $role='Common';
         }
     }
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'user', 'action' => 'login'));
         return false;
     }
 }
开发者ID:alexz202,项目名称:goldenlight,代码行数:34,代码来源:Security.php

示例11: registerServices

 /**
  * Register specific services for the module
  */
 public function registerServices(DiInterface $di)
 {
     // Assign our new tag a definition so we can call it
     $di->set('Utilitarios', function () {
         return new \Ecommerce\Admin\Helpers\UtilitariosHelper();
     });
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Ecommerce\\Admin\\Controllers');
         return $dispatcher;
     });
     // Registering the view component
     $di->set('view', function () {
         $config = (include __DIR__ . "/config/config.php");
         $view = new View();
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir('../apps/admin/views/');
         return $view;
     });
     include "../apps/admin/vendor/autoload.php";
 }
开发者ID:denners777,项目名称:phalcon_ecommerce,代码行数:28,代码来源:Module.php

示例12: afterExecuteRoute

 /**
  * This action is executed after execute any action in the application.
  *
  * @param PhalconEvent $event      Event object.
  * @param Dispatcher   $dispatcher Dispatcher object.
  *
  * @return mixed
  */
 public function afterExecuteRoute(PhEvent $event, Dispatcher $dispatcher)
 {
     $config = $this->getDI()->get('config')->toArray();
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     $this->getDI()->get('view')->pick($controllerName . '/' . $config['global']['template'][$controllerName] . '/' . $actionName);
 }
开发者ID:nguyenducduy,项目名称:phblog,代码行数:15,代码来源:Template.php

示例13: registerServices

 /**
  * Registration services for specific module
  * @param \Phalcon\DI $di
  * @access public
  * @return mixed
  */
 public function registerServices($di)
 {
     // Dispatch register
     $di->set('dispatcher', function () use($di) {
         $eventsManager = $di->getShared('eventsManager');
         $eventsManager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) {
             switch ($exception->getCode()) {
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                 case \Phalcon\Mvc\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                     $dispatcher->forward(['module' => self::MODULE, 'namespace' => 'Modules\\' . self::MODULE . '\\Controllers\\', 'controller' => 'error', 'action' => 'notFound']);
                     return false;
                     break;
                 default:
                     $dispatcher->forward(['module' => self::MODULE, 'namespace' => 'Modules\\' . self::MODULE . '\\Controllers\\', 'controller' => 'error', 'action' => 'uncaughtException']);
                     return false;
                     break;
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         $dispatcher->setEventsManager($eventsManager);
         $dispatcher->setDefaultNamespace('Modules\\' . self::MODULE . '\\Controllers');
         return $dispatcher;
     }, true);
     // Registration of component representations (Views)
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir($this->_config['application']['viewsFront'])->setMainView('layout');
         return $view;
     });
     return require_once APP_PATH . '/Modules/' . self::MODULE . '/config/services.php';
 }
开发者ID:stanislav-web,项目名称:phalcon-development,代码行数:37,代码来源:Module.php

示例14: registerServices

 /**
  * Registers the module-only services
  *
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices($di)
 {
     /**
      * Read application wide and module only configurations
      */
     $appConfig = $di->get('config');
     $moduleConfig = (include __DIR__ . '/config/config.php');
     $di->set('moduleConfig', $moduleConfig);
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($appConfig) {
         $url = new UrlResolver();
         $url->setBaseUri($appConfig->application->baseUri);
         return $url;
     });
     /**
      * Module specific dispatcher
      */
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setEventsManager($di->getShared('eventsManager'));
         $dispatcher->setDefaultNamespace('App\\Modules\\Oauth\\');
         return $dispatcher;
     });
     /**
      * Module specific database connection
      */
     $di->set('db', function () use($appConfig) {
         return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]);
     });
 }
开发者ID:sarahsampan,项目名称:compare-api,代码行数:37,代码来源:Module.php

示例15: beforeException

 public function beforeException(Event $event, Dispatcher $dispatcher, \Exception $e)
 {
     $this->getLogger()->exception($e);
     $this->response->setStatusCode($e->getCode() ?: 500, $e->getMessage() ?: 'Application error');
     $dispatcher->forward(['namespace' => 'Controller', 'controller' => 'error', 'action' => 'index', 'params' => [0 => $e->getMessage()]]);
     return false;
 }
开发者ID:aisuhua,项目名称:vkplay,代码行数:7,代码来源:Exception.php


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