From 99d29eb48fafc4fc5c5a4c4479e90158eedf12b0 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 28 May 2016 11:20:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view/driver/Php.php | 15 ++++++++------- library/think/view/driver/Think.php | 17 ++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 3063bc02..abd980f3 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -39,7 +39,7 @@ class Php */ public function exists($template) { - if (!is_file($template)) { + if ('' == pathinfo($template, PATHINFO_EXTENSION)) { // 获取模板文件名 $template = $this->parseTemplate($template); } @@ -55,7 +55,7 @@ class Php */ public function fetch($template, $data = []) { - if (!is_file($template)) { + if ('' == pathinfo($template, PATHINFO_EXTENSION)) { // 获取模板文件名 $template = $this->parseTemplate($template); } @@ -94,17 +94,17 @@ class Php $this->config['view_path'] = VIEW_PATH; } - $depr = $this->config['view_depr']; - $template = str_replace(['/', ':'], $depr, $template); if (strpos($template, '@')) { list($module, $template) = explode('@', $template); - $path = APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . VIEW_LAYER . DS; + $path = APP_PATH . $module . DS . VIEW_LAYER . DS; } else { $path = $this->config['view_path']; } // 分析模板文件规则 - if (defined('CONTROLLER_NAME')) { + if (defined('CONTROLLER_NAME') && 0 !== strpos($template, '/')) { + $depr = $this->config['view_depr']; + $template = str_replace(['/', ':'], $depr, $template); if ('' == $template) { // 如果模板文件名为空 按照默认规则定位 $template = str_replace('.', DS, CONTROLLER_NAME) . $depr . ACTION_NAME; @@ -112,7 +112,8 @@ class Php $template = str_replace('.', DS, CONTROLLER_NAME) . $depr . $template; } } - return $path . $template . '.' . ltrim($this->config['view_suffix'], '.'); + return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.'); + } } diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index 8eb85e26..167bd36f 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -48,7 +48,7 @@ class Think */ public function exists($template) { - if (!is_file($template)) { + if ('' == pathinfo($template, PATHINFO_EXTENSION)) { // 获取模板文件名 $template = $this->parseTemplate($template); } @@ -65,7 +65,7 @@ class Think */ public function fetch($template, $data = [], $config = []) { - if (!is_file($template)) { + if ('' == pathinfo($template, PATHINFO_EXTENSION)) { // 获取模板文件名 $template = $this->parseTemplate($template); } @@ -99,17 +99,20 @@ class Think */ private function parseTemplate($template) { - $depr = $this->config['view_depr']; - $template = str_replace(['/', ':'], $depr, $template); + // 获取视图根目录 if (strpos($template, '@')) { + // 跨模块调用 list($module, $template) = explode('@', $template); - $path = APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . VIEW_LAYER . DS; + $path = APP_PATH . $module . DS . VIEW_LAYER . DS; } else { + // 当前视图目录 $path = $this->config['view_path']; } // 分析模板文件规则 - if (defined('CONTROLLER_NAME')) { + if (defined('CONTROLLER_NAME') && 0 !== strpos($template, '/')) { + $depr = $this->config['view_depr']; + $template = str_replace(['/', ':'], $depr, $template); if ('' == $template) { // 如果模板文件名为空 按照默认规则定位 $template = str_replace('.', DS, CONTROLLER_NAME) . $depr . ACTION_NAME; @@ -117,7 +120,7 @@ class Think $template = str_replace('.', DS, CONTROLLER_NAME) . $depr . $template; } } - return $path . $template . '.' . ltrim($this->config['view_suffix'], '.'); + return $path . ltrim($template, '/') . '.' . ltrim($this->config['view_suffix'], '.'); } public function __call($method, $params)