From d632d6bd074fd8bc298d5187ce0df3cedf1f0524 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 1 Aug 2016 11:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BUrl=E7=B1=BB=E7=9A=84build?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E5=AE=8C=E5=96=84=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=91=BD=E5=90=8D=E6=A0=87=E8=AF=86=E7=9A=84=E7=94=9F?= =?UTF-8?q?=E6=88=90=20=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8=20build('[name?= =?UTF-8?q?]');=20=E6=A0=B9=E6=8D=AE=E8=B7=AF=E7=94=B1=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E5=BF=AB=E9=80=9F=E7=94=9F=E6=88=90=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=20=E5=A6=82=E6=9E=9C=E8=AF=A5=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=88=96=E8=80=85?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=B8=8D=E5=8C=B9=E9=85=8D=20=E5=88=99?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= 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 9fe9d1fc..8b8eb3e3 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -39,6 +39,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'])) { @@ -69,10 +74,12 @@ class Url $vars = array_merge($params, $vars); } - $rule = Route::name($url); + $rule = Route::name(isset($name) ? $name : $url); if ($rule && $match = self::getRuleUrl($rule, $vars)) { // 匹配路由命名标识 快速生成 $url = $match; + } elseif ($rule && isset($name)) { + throw new \InvalidArgumentException('route name not exists:' . $name); } else { // 获取路由别名 $alias = self::getRouteAlias();