From 3e22f21d34acd9b4e3ebbd201283b9e6d3856926 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 17:03:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=9B=BF=E6=8D=A2=E5=AD=97=E7=AC=A6=E4=B8=B2=20=5F=5F?= =?UTF-8?q?ROOT=5F=5F=20=5F=5FSTATIC=5F=5F=20=5F=5FJS=5F=5F=20=5F=5FCSS=5F?= =?UTF-8?q?=5F=20=5F=5FURL=5F=5F=20=E9=83=BD=E4=B8=8D=E5=B8=A6=E5=9F=9F?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/library/think/View.php b/library/think/View.php index 5fb9a142..ede7cd44 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -11,6 +11,9 @@ namespace think; +use think\Loader; +use think\Request; + class View { // 视图实例 @@ -30,11 +33,25 @@ class View * @param array $engine 模板引擎参数 * @param array $replace 字符串替换参数 */ - public function __construct($engine = [], $replace = []) + public function __construct($engine = [], array $replace = []) { // 初始化模板引擎 $this->engine((array) $engine); - $this->replace = $replace; + // 基础替换字符串 + $request = Request::instance(); + $base = $request->root(); + $root = strpos($base, '.') ? dirname($base) : $base; + if ('' != $root) { + $root = '/' . $root; + } + $baseReplace = [ + '__ROOT__' => $root, + '__URL__' => $base . '/' . $request->module() . '/' . Loader::parseName($request->controller()), + '__STATIC__' => $root . '/static', + '__CSS__' => $root . '/static/css', + '__JS__' => $root . '/static/js', + ]; + $this->replace = array_merge($baseReplace, $replace); } /**