From 5e6fba19201a75583296be0dd55ee6c00ceff795 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 5 Jul 2016 13:55:03 +0800 Subject: [PATCH] =?UTF-8?q?Url=E7=B1=BB=E5=A2=9E=E5=8A=A0root=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E7=94=A8=E4=BA=8E=E6=8C=87=E5=AE=9AURL=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=9A=84root=EF=BC=88=E4=B8=8D=E5=90=AB=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Url.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/think/Url.php b/library/think/Url.php index 5f802011..47054bd9 100644 --- a/library/think/Url.php +++ b/library/think/Url.php @@ -19,6 +19,9 @@ use think\Route; class Url { + // 生成URL地址的root + protected static $root; + /** * URL生成 支持路由反射 * @param string $url URL表达式, @@ -113,7 +116,7 @@ class Url // 检测域名 $domain = self::parseDomain($url, $domain); // URL组装 - $url = $domain . Request::instance()->root() . '/' . ltrim($url, '/'); + $url = $domain . (self::$root ?: Request::instance()->root()) . '/' . ltrim($url, '/'); return $url; } @@ -366,4 +369,11 @@ class Url { Cache::rm('think_route_map'); } + + // 指定当前生成URL地址的root + public static function root($root) + { + self::$root = $root; + Request::instance()->root($root); + } }