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


PHP Dispatcher::getControllerName方法代码示例

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


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

示例1: beforeExecuteRoute

 /**
  * @param Dispatcher $dispatcher
  *
  * @return bool
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $returnVal = true;
     $lang = $this->getUriParameter('language');
     $controllerName = $dispatcher->getControllerName();
     if ('1' != $this->config->application->debug) {
         $lang = $this->getUriParameter('language');
         $lang = $lang ? $lang : 'en';
         $key = preg_replace('/[^a-zA-Z0-9\\_]/', '', $lang . '-' . $dispatcher->getControllerName() . '-' . $dispatcher->getActionName() . '-' . implode('-', $dispatcher->getParams()));
         $this->view->cache(array('key' => $key));
         if ($this->view->getCache()->exists($key)) {
             $returnVal = false;
         }
     }
     $auth = $this->session->get('auth');
     $identity = $this->auth->getIdentity();
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = $identity['profile'];
     }
     // Check if the user have permission to the current option
     $actionName = $dispatcher->getActionName();
     if (!$this->acl->isAllowed($role, $controllerName, $actionName)) {
         $this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
         if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
             $dispatcher->forward(array('controller' => $controllerName, 'action' => 'index'));
         }
         $returnVal = false;
     } else {
         $this->requestInitialize($controllerName);
     }
     return $returnVal;
 }
开发者ID:phil-schreiber,项目名称:messewebsite,代码行数:39,代码来源:ControllerBase.php

示例2: 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

示例3: beforeExecuteRoute

 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'INVITADO';
     } else {
         $role = $auth["rol_nombre"];
     }
     //nombre del controlador al que intentamos acceder
     $controller = $dispatcher->getControllerName();
     //nombre de la acción a la que intentamos acceder
     $action = $dispatcher->getActionName();
     //obtenemos la Lista de Control de Acceso(acl) que hemos creado
     $acl = $this->getAcl();
     //boolean(true | false) si tenemos permisos devuelve true en otro caso false
     $allowed = $acl->isAllowed($role, $controller, $action);
     //si el usuario no tiene acceso a la zona que intenta acceder
     //se lo redirecciona a login. (o habria que enviarlo al index? )
     //con un mensaje flash
     if ($allowed != \Phalcon\Acl::ALLOW) {
         $this->flash->error("<p>ZONA RESTRINGIDA, NO TIENES PERMISO PARA ACCEDER A LA SECCIÓN SOLICITADA</p>");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         return false;
     }
 }
开发者ID:munozdaniel,项目名称:sya,代码行数:25,代码来源:Seguridad.php

示例4: beforeExecuteRoute

 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     // Check whether the "auth" variable exists in session to define the active role
     $auth = $this->session->get('auth');
     if (!$auth) {
         $role = 'Guests';
     } else {
         $role = 'Users';
     }
     // Take the active controller/action from the dispatcher
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     // Obtain the ACL list
     $acl = $this->getAcl();
     // Check if the Role have access to the controller (resource)
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         // If he doesn't have access forward him to the index controller
         $this->flash->error("You don't have access to this module");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         // Returning "false" we tell to the dispatcher to stop the current operation
         return false;
     }
     //return true;
 }
开发者ID:Xavier94,项目名称:mydav,代码行数:25,代码来源:SecurityPlugin.php

示例5: routeFromHere

 /**
  * Generate a route based on the current URL.
  *
  * @param $path_info
  * @return string The routed URL.
  */
 public function routeFromHere($path_info)
 {
     $new_path = array('module' => $this->_dispatcher->getModuleName(), 'controller' => $this->_dispatcher->getControllerName(), 'action' => $this->_dispatcher->getActionName(), 'params' => (array) $this->_dispatcher->getParams());
     if (isset($path_info['module'])) {
         $new_path['module'] = $path_info['module'];
         unset($path_info['module']);
     }
     if (isset($path_info['controller'])) {
         $new_path['controller'] = $path_info['controller'];
         unset($path_info['controller']);
     }
     if (isset($path_info['action'])) {
         $new_path['action'] = $path_info['action'];
         unset($path_info['action']);
     }
     if (count($path_info) > 0) {
         foreach ((array) $path_info as $param_key => $param_value) {
             $new_path['params'][$param_key] = $param_value;
         }
     }
     if (isset($new_path['params']['name'])) {
         // Allow support for named routes.
         $route_name = $new_path['params']['name'];
         unset($new_path['params']['name']);
         return $this->named($route_name, $new_path['params']);
     } else {
         return $this->route($new_path);
     }
 }
开发者ID:einstein95,项目名称:FAOpen,代码行数:35,代码来源:Url.php

示例6: beforeDispatch

 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     //check whether the 'auth' variable exists in session (if logged in)
     $auth = $this->session->get('auth');
     if ($auth) {
         //logged in
         $role = 'Users';
     } else {
         //not logged in
         $role = 'Guests';
     }
     //take the active controller/action from the dispatcher
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     //obtain the ACL list
     $acl = $this->getAcl(false);
     //check if the role has access to the controller (resource)
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         //does not have access to the controller, fwd to index
         $this->flashSession->error("{$role} don't have access to this page!");
         $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
         //return false to tell dispatcher to stop current operation
         return false;
     } else {
         //user is allowed in (do nothing)
         if ($controller == 'admin' && $action == 'updateAcl') {
             //update acl
             $acl = $this->getAcl(true);
         }
     }
 }
开发者ID:freesaga,项目名称:getit,代码行数:32,代码来源:Security.php

示例7: beforeExecuteRoute

 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     echo $resource = $this->_module . '-' . $dispatcher->getControllerName(), PHP_EOL;
     // frontend-dashboard
     echo $access = $dispatcher->getActionName();
     // null
 }
开发者ID:abuelezz,项目名称:mvc,代码行数:7,代码来源:Acl.php

示例8: beforeExecuteRoute

 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $actionName = $dispatcher->getActionName();
     $controllerName = $dispatcher->getControllerName() . 'Controller';
     $nameSpaceName = $dispatcher->getNamespaceName();
     $className = $nameSpaceName . '\\' . ucwords($controllerName);
     $no_auth_array = [];
     if (class_exists($className)) {
         $no_auth_array = array_merge($className::$no_auth_array, self::$no_auth_array);
     }
     if (in_array($actionName, $no_auth_array)) {
         return true;
     }
     if ($this->isLogin()) {
         //判断是否有权限操作此资源
         if (!$this->isAllowed($actionName)) {
             //echo '没有权限';
             $dispatcher->forward(array('controller' => 'index', 'action' => 'noauth'));
             //die();
             return false;
         }
         return true;
     } else {
         if (!($host = $this->request->getServerName())) {
             $host = $this->request->getHttpHost();
         }
         $sourceUrl = $this->request->getScheme() . '://' . $host . $this->request->getURI();
         $url = $this->request->getScheme() . '://' . $host . self::USER_LOGIN_URL . '?ref=' . $sourceUrl;
         $this->redirect($url);
     }
 }
开发者ID:abc2001x,项目名称:phalcon_mode,代码行数:31,代码来源:AdminAuthController.php

示例9: 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

示例10: beforeExecuteRoute

 /**
  * Execute before the router so we can determine if this is a provate controller, and must be authenticated, or a
  * public controller that is open to all.
  *
  * @param Dispatcher $dispatcher
  * @return boolean
  */
 public function beforeExecuteRoute(Dispatcher $dispatcher)
 {
     $controllerName = $dispatcher->getControllerName();
     // Only check permissions on private controllers
     if ($this->acl->isPrivate($controllerName)) {
         // Get the current identity
         $identity = $this->auth->getIdentity();
         // If there is no identity available the user is redirected to index/index
         if (!is_array($identity)) {
             $this->flash->notice('You don\'t have access to this module: private');
             $dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             return false;
         }
         // Check if the user have permission to the current option
         $actionName = $dispatcher->getActionName();
         if (!$this->acl->isAllowed($identity['profile'], $controllerName, $actionName)) {
             $this->flash->notice('You don\'t have access to this module: ' . $controllerName . ':' . $actionName);
             if ($this->acl->isAllowed($identity['profile'], $controllerName, 'index')) {
                 $dispatcher->forward(array('controller' => $controllerName, 'action' => 'index'));
             } else {
                 $dispatcher->forward(array('controller' => 'user_control', 'action' => 'index'));
             }
             return false;
         }
     }
 }
开发者ID:sbarrios,项目名称:exclie_soap,代码行数:33,代码来源:ControllerBase.php

示例11: beforeDispatch

 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $controller = \strtolower($dispatcher->getControllerName());
     $action = \strtolower($dispatcher->getActionName());
     $resource = "{$controller}::{$action}";
     $role = 'GUEST';
     if ($this->session->get('authenticated')) {
         $user = User::findFirstByIdUser($this->session->get('idUser'));
         if ($user) {
             $role = $user->role->name;
             $userEfective = new stdClass();
             $userEfective->enable = false;
             $efective = $this->session->get('userEfective');
             if (isset($efective)) {
                 $userEfective->enable = true;
                 $role = $efective->role->name;
                 $user->role = $efective->role;
             }
             // Inyectar el usuario
             $this->_dependencyInjector->set('userData', $user);
             $this->_dependencyInjector->set('userEfective', $userEfective);
         }
     }
     $map = $this->getControllerMap();
     $this->publicurls = array('error::index', 'error::notavailable', 'error::unauthorized', 'error::forbidden', 'session::login', 'session::logout', 'session::recoverpass', 'session::resetpassword', 'session::setnewpass', 'session::questionpass', 'session::changepass');
     if ($role == 'GUEST') {
         if (!in_array($resource, $this->publicurls)) {
             $this->response->redirect("session/login");
             return false;
         }
     } else {
         if ($resource == 'session::login') {
             $this->response->redirect("index");
             return false;
         } else {
             $acl = $this->getAcl();
             $this->logger->log("Validando el usuario con rol [{$role}] en [{$resource}]");
             if (!isset($map[$resource])) {
                 $this->logger->log("El recurso no se encuentra registrado");
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'index'));
                 return false;
             }
             $reg = $map[$resource];
             foreach ($reg as $resources => $actions) {
                 foreach ($actions as $act) {
                     if (!$acl->isAllowed($role, $resources, $act)) {
                         $this->logger->log('Acceso denegado');
                         $dispatcher->forward(array('controller' => 'error', 'action' => 'forbidden'));
                         return false;
                     }
                 }
             }
             $mapForLoginLikeAnyUser = array('session::superuser');
             if (in_array($resource, $mapForLoginLikeAnyUser)) {
                 $this->session->set('userEfective', $user);
             }
             return true;
         }
     }
 }
开发者ID:dorianlopez,项目名称:surticreditos,代码行数:63,代码来源:Security.php

示例12: 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

示例13: beforeExecuteRoute

 /**
  * This action is executed before execute any action in the application
  *
  * @param Event $event
  * @param Dispatcher $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $module = $dispatcher->getModuleName();
     $controller = $module . ':' . $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $auth = $this->auth->getIdentity();
     $role = 'Visitante';
     $url = '/' . $module;
     $name = '';
     if (!$auth) {
         $this->auth->setGuest($name, $role, $url);
     } else {
         if ($auth['usuario_tipo'] == 'Visitante' && $action != 'auth') {
             if ($auth['home'] != $url) {
                 $this->auth->setGuest($name, $role, $url);
             }
         } else {
             $role = $auth['usuario_tipo'];
         }
     }
     $acl = $this->getAcl();
     $allowed = $acl->isAllowed($role, $controller, $action);
     if ($allowed != Acl::ALLOW) {
         $dispatcher->forward(array('controller' => 'errors', 'action' => 'show401'));
         return false;
     }
 }
开发者ID:zedmaster,项目名称:ticobox,代码行数:34,代码来源:Security.php

示例14: 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

示例15: 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


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