From e255100c7f162c48a22f1c2bf0890469f54f061b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 24 Apr 2018 12:18:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF=E5=BC=95?= =?UTF-8?q?=E6=93=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 1 + library/think/template/driver/File.php | 15 +++++-------- library/think/view/driver/Php.php | 30 +++++++++----------------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index ac7718b1..f940d28b 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1527,6 +1527,7 @@ class Route * 解析URL地址为 模块/控制器/操作 * @access private * @param string $url URL地址 + * @param bool $convert 是否自动转换URL地址 * @return array */ private static function parseModule($url, $convert = false) diff --git a/library/think/template/driver/File.php b/library/think/template/driver/File.php index f7fa8c89..a9a86bf2 100644 --- a/library/think/template/driver/File.php +++ b/library/think/template/driver/File.php @@ -15,6 +15,8 @@ use think\Exception; class File { + protected $cacheFile; + /** * 写入编译缓存 * @param string $cacheFile 缓存的文件名 @@ -42,20 +44,13 @@ class File */ public function read($cacheFile, $vars = []) { + $this->cacheFile = $cacheFile; if (!empty($vars) && is_array($vars)) { // 模板阵列变量分解成为独立变量 - if (isset($vars['cacheFile'])) { - $_think_cacheFile = $cacheFile; - $cacheFile = $vars['cacheFile']; - unset($vars['cacheFile'], $vars['_think_cacheFile']); - extract($vars, EXTR_OVERWRITE); - include $_think_cacheFile; - return; - } - extract($vars); + extract($vars, EXTR_OVERWRITE); } //载入模版缓存文件 - include $cacheFile; + include $this->cacheFile; } /** diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 47c9dc10..b5ebe133 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -32,6 +32,8 @@ class Php // 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 'auto_rule' => 1, ]; + protected $template; + protected $content; public function __construct($config = []) { @@ -70,18 +72,12 @@ class Php if (!is_file($template)) { throw new TemplateNotFoundException('template not exists:' . $template, $template); } + $this->template = $template; // 记录视图信息 App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info'); - if (isset($data['template'])) { - $__template__ = $template; - $template = $data['template']; - unset($data['template'], $data['__template__']); - extract($data, EXTR_OVERWRITE); - include $__template__; - } else { - extract($data, EXTR_OVERWRITE); - include $template; - } + + extract($data, EXTR_OVERWRITE); + include $template; } /** @@ -93,16 +89,10 @@ class Php */ public function display($content, $data = []) { - if (isset($data['content'])) { - $__content__ = $content; - $content = $data['content']; - unset($data['content'], $data['__content__']); - extract($data, EXTR_OVERWRITE); - eval('?>' . $__content__); - } else { - extract($data, EXTR_OVERWRITE); - eval('?>' . $content); - } + $this->content = $content; + + extract($data, EXTR_OVERWRITE); + eval('?>' . $this->content); } /**