From b9b7e34b6d8c13e6a6286ad505ad70accf9c09e4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 13 Oct 2016 23:34:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index 77c15a2f..79e3c1cb 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -35,6 +35,11 @@ class Url $domain = true; } // 解析URL + if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { + // [name] 表示使用路由命名标识生成URL + $name = substr($url, 1, $pos - 1); + $url = 'name' . substr($url, $pos + 1); + } $info = parse_url($url); $url = !empty($info['path']) ? $info['path'] : ''; if (isset($info['fragment'])) { @@ -60,7 +65,7 @@ class Url } if ($url) { - $rule = Route::name($url . (isset($info['query']) ? '?' . $info['query'] : '')); + $rule = Route::name(isset($name) ? $name : $url . (isset($info['query']) ? '?' . $info['query'] : '')); if (is_null($rule) && isset($info['query'])) { $rule = Route::name($url); // 解析地址里面参数 合并到vars @@ -77,6 +82,8 @@ class Url if (!empty($match[1])) { $domain = $match[1]; } + } elseif (!empty($rule) && isset($name)) { + throw new \InvalidArgumentException('route name not exists:' . $name); } else { // 检查别名路由 $alias = Route::rules('alias');