Example #1
0
 /**
  * 重定向请求到新的url地址
  * 
  * 重定向请求到新的url地址是通过head方式重新开启一个url访问请求.
  * @param WindForward $forward
  * @param AbstractWindRouter $router
  * @return void
  */
 protected function dispatchWithRedirect($forward, $router)
 {
     if (!($_url = $forward->getUrl())) {
         $_url = $router->assemble($forward->getAction(), $forward->getArgs());
     }
     $_url = WindUrlHelper::checkUrl($_url, true);
     $this->getResponse()->sendRedirect($_url);
 }
 /**
  * 在此路由协议的基础上组装url
  *
  * @param AbstractWindRouter $router
  * @param string $action 格式为app/module/controller/action
  * @param array $args 附带的参数
  * @return string
  * @see AbstractWindRoute::build()
  */
 public function build($router, $action, $args = array())
 {
     list($_a, $_c, $_m, $_p, $args) = WindUrlHelper::resolveAction($action, $args);
     $flag = 0;
     foreach ($this->params as $key => $val) {
         if (!isset($val['map'])) {
             continue;
         }
         if ($key === $router->getModuleKey()) {
             $m = $_m ? $_m : $router->getModule();
             if ($m === $router->getDefaultModule() && $flag & 2) {
                 $flag = 7;
             } else {
                 $_args[$val['map']] = $m;
             }
         } elseif ($key === $router->getControllerKey()) {
             $c = $_c ? $_c : $router->getController();
             if ($c === $router->getDefaultController() && $flag & 1) {
                 $flag = 3;
             } else {
                 $_args[$val['map']] = $c;
             }
         } elseif ($key === $router->getActionKey()) {
             $a = $_a ? $_a : $router->getAction();
             if ($a === $router->getDefaultAction()) {
                 $flag = 1;
             } else {
                 $_args[$val['map']] = $a;
             }
         } else {
             if (isset($args[$key])) {
                 $_args[$val['map']] = $args[$key];
             } elseif (isset($val['value'])) {
                 $_args[$val['map']] = $val['value'];
             } else {
                 $_args[$val['map']] = '';
             }
         }
         unset($args[$key]);
     }
     $mulitipyTime = count($_args);
     $_args[0] = str_repeat($this->reverse, $mulitipyTime);
     ksort($_args);
     $url = call_user_func_array("sprintf", $_args);
     $args && ($url .= '?' . WindUrlHelper::argsToUrl($args, true, $this->separator));
     $baseUrl = Wind::getApp()->getRequest()->getBaseUrl(true);
     $_baseUrl = $_p ? $this->replaceStr($baseUrl, $_p) : $baseUrl;
     return trim($_baseUrl, '/') . '/' . trim($url, '/');
 }
Example #3
0
 /**
  * 在此路由协议的基础上组装url
  *
  * @param AbstractWindRouter $router        	
  * @param string $action
  *        	格式为app/module/controller/action
  * @param array $args
  *        	附带的参数
  * @return string
  * @see AbstractWindRoute::build()
  */
 public function build($router, $action, $args = array())
 {
     list($_a, $_c, $_m, $_p, $args) = WindUrlHelper::resolveAction($action, $args);
     foreach ($this->params as $key => $val) {
         if ($key === $router->getModuleKey()) {
             $_m || ($_m = $router->getModule());
             $_args[$val] = $_m;
         } elseif ($key === $router->getControllerKey()) {
             $_c || ($_c = $router->getController());
             $_args[$val] = $_c;
         } elseif ($key === $router->getActionKey()) {
             $_a || ($_a = $router->getAction());
             $_args[$val] = $_a;
         }
         unset($args[$key]);
     }
     $_args[0] = $this->reverse;
     ksort($_args);
     $url = call_user_func_array("sprintf", $_args);
     $args && ($url .= '/' . WindUrlHelper::argsToUrl($args, true, $this->separator));
     return trim($url, '/');
 }
Example #4
0
 /**
  * 分析参数
  *
  * @param AbstractWindRouter $router
  * @param string $action
  * @param array $args
  * @return array 
  */
 private function _resolveMca($router, $action, $args)
 {
     list($action, $_args) = explode('?', $action . '?');
     $args = array_merge($args, $_args ? WindUrlHelper::urlToArgs($_args, false) : array());
     $action = trim($action, '/');
     $tmp = explode('/', $action . '/');
     end($tmp);
     if (5 === count($tmp) && !strncasecmp('app/', $action, 4)) {
         list($_a, $_c, $_app_name, $_m) = array(prev($tmp), prev($tmp), prev($tmp), prev($tmp));
         $args['app'] = $_app_name;
     } else {
         list($_a, $_c, $_m) = array(prev($tmp), prev($tmp), prev($tmp));
     }
     $_m = $_m ? $_m : $router->getDefaultModule();
     $_c = $_c ? $_c : $router->getDefaultController();
     $_a = $_a ? $_a : $router->getDefaultAction();
     return array($_m, $_c, $_a, $args);
 }