Exemple #1
0
 public function routerShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
 {
     //不需要权限验证的模块
     $no_require = array('Login' => null);
     //不需要管理员权限的模块
     $admin_require = array('Log' => null, 'Orders' => null, 'Accountgroup' => null, 'Index' => null);
     $is_admin = Yaf\Session::getInstance()->get('is_admin');
     //权限控制
     if (in_array($request->getControllerName(), array_keys($no_require))) {
         return;
     }
     if (!in_array($request->getControllerName(), array_keys($admin_require)) && $is_admin !== '1') {
         $request->setModuleName('Index');
         $request->setControllerName('Login');
         $request->setActionName('get');
         echo 3;
         die;
         return;
     }
     if (!in_array($request->getControllerName(), array_keys($admin_require)) && $is_admin === '0') {
         $request->setModuleName('Index');
         $request->setControllerName('Error');
         $request->setActionName('auth');
         return;
     }
 }
Exemple #2
0
 public function routerShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
 {
     /* 验证是否为命令行方式 */
     if ($request->isCli()) {
         $action = $request->getActionName();
         $locate_param = strpos($request->getRequestUri(), '?');
         $locate = strpos($request->getActionName(), '?');
         /* 验证action是否有传参 */
         if ($locate !== false) {
             $query_list = array();
             //重新设置action
             $request->setActionName(substr($action, 0, $locate));
             //截取query_string
             $query_string = substr($request->getRequestUri(), $locate_param + 1);
             //解析query_string
             parse_str($query_string, $query_list);
             //循环set到param
             foreach ($query_list as $key => $value) {
                 $request->setParam($key, $value);
             }
         }
     }
     $request_uri = strtolower($request->getModuleName() . '/' . $request->getControllerName() . '/' . $request->getActionName());
     $request->setRequestUri($request_uri);
     $request->setModuleName(ucfirst($request->getModuleName()));
     $request->setControllerName(underline_to_camel(ucfirst($request->getControllerName())));
     $request->setActionName(underline_to_camel($request->getActionName()));
     /* 保存请求地址 */
     Yaf\Registry::set('request_uri', $request_uri);
 }