改进Url生成的别名获取后的域名和后缀拼接

This commit is contained in:
thinkphp
2016-01-09 21:53:15 +08:00
parent 25f31081e8
commit f779f2ca07

View File

@@ -26,10 +26,6 @@ class Url
*/ */
public static function build($url = '', $vars = '', $suffix = true, $domain = true) public static function build($url = '', $vars = '', $suffix = true, $domain = true)
{ {
// 检测是否存在路由别名
if ($aliasUrl = Route::getRouteUrl($url, $vars)) {
return $aliasUrl;
}
// 解析参数 // 解析参数
if (is_string($vars)) { if (is_string($vars)) {
// aaa=1&bbb=2 转换成数组 // aaa=1&bbb=2 转换成数组
@@ -44,8 +40,13 @@ class Url
$vars = array_merge($params, $vars); $vars = array_merge($params, $vars);
} }
// 检测是否存在路由别名
if ($aliasUrl = Route::getRouteUrl($url, $vars)) {
// 存在别名定义则优先
return $aliasUrl;
} else {
// 检测路由 // 检测路由
$match = self::checkRoute($url, $vars, $domain, $type); $match = self::checkRoute($url, $vars, $domain);
if (false === $match) { if (false === $match) {
// 路由不存在 直接解析 // 路由不存在 直接解析
if (false !== strpos($url, '\\')) { if (false !== strpos($url, '\\')) {
@@ -68,6 +69,8 @@ class Url
// 处理路由规则中的特殊内容 // 处理路由规则中的特殊内容
$url = str_replace(['\\d', '$'], '', $match); $url = str_replace(['\\d', '$'], '', $match);
} }
}
// 检测URL绑定 // 检测URL绑定
$type = Route::bind('type'); $type = Route::bind('type');
if ($type) { if ($type) {