Ejemplo n.º 1
0
 public function beforeExecuteRoute($event, DispatcherInterface $dispatcher)
 {
     $defaultNamespace = $dispatcher->getDefaultNamespace();
     $namespace = $dispatcher->getNamespaceName();
     if (strpos($namespace, $defaultNamespace) === 0) {
         $namespace = substr($namespace, strlen($defaultNamespace));
     }
     $parts = array_filter(explode('\\', strtolower($namespace)));
     $parts[] = $dispatcher->getControllerName();
     $parts[] = $dispatcher->getActionName();
     $this->view->pick(implode(DIRECTORY_SEPARATOR, $parts));
 }
Ejemplo n.º 2
0
 /**
  * @param \Phalcon\Mvc\Dispatcher|\Phalcon\Mvc\DispatcherInterface $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute($dispatcher)
 {
     $this->operator = new OperatorIdentity();
     $this->operator->cookies = $this->cookies;
     $this->operator->load();
     // 判断登录
     $moduleConfig = $this->di->get('moduleConfig');
     $controllerName = $dispatcher->getControllerName();
     $actionName = $dispatcher->getActionName();
     if ($controllerName == $moduleConfig->operator->login->controller && $actionName == $moduleConfig->operator->login->action) {
         return true;
     }
     if ($this->operator->isLogin()) {
         // 判断权限
         $result = OperatorGroupRight::verify($this->operator->group, $controllerName, $actionName, $dispatcher->getDI());
         // 权限不足,输出错误
         if (!$result) {
             $content = '';
             if ($this->request->isAjax()) {
                 $resp = new ResponseResult();
                 $resp->sendError(ResponseResultStatus::RIGHT_VERIFY_FAIL, '权限不足!');
                 $content = $resp->getContent();
             } else {
                 $content = '访问权限不足!';
             }
             $this->view->disable();
             echo $content;
         }
         return $result;
     }
     if ($this->request->isAjax()) {
         $resp = new ResponseResult();
         $resp->sendError(ResponseResultStatus::USER_TOKEN_EXPIRES, '未登录!');
         echo $resp->getContent();
     } else {
         $this->response->redirect($moduleConfig->operator->login->url);
     }
     $this->view->disable();
     return false;
 }
 /**
  * Start execute route benchmark
  *
  * @param Event $event
  * @param DispatcherInterface $dispatcher
  */
 public function beforeExecuteRoute(Event $event, DispatcherInterface $dispatcher)
 {
     $name = get_class($event->getSource()) . '::executeRoute';
     $metadata = ['executed' => sprintf('%s::%sAction', get_class($dispatcher->getActiveController()), $dispatcher->getActionName()), 'controller' => $dispatcher->getControllerName(), 'action' => $dispatcher->getActionName(), 'params' => $dispatcher->getParams()];
     $this->benchmarkRoute = $this->getProfiler()->start($name, $metadata, 'Dispatcher');
 }