/** * 在此路由协议的基础上组装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, '/'); }
/** * 在此路由协议的基础上组装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, '/'); }