From 952d18af1703916a49d3f7b67d3d37a89840c0bb Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 20 May 2016 11:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E5=9B=BE=E9=A9=B1=E5=8A=A8=E7=B1=BB?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0exists=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=A8=A1=E6=9D=BF=E6=96=87=E4=BB=B6=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view/driver/Php.php | 21 ++++++++++++++++----- library/think/view/driver/Think.php | 21 ++++++++++++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 0b6edbac..b22d4612 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -31,6 +31,21 @@ class Php $this->config = array_merge($this->config, $config); } + /** + * 检测是否存在模板文件 + * @access public + * @param string $template 模板文件或者模板规则 + * @return bool + */ + public function exists($template) + { + if (!is_file($template)) { + // 获取模板文件名 + $template = $this->parseTemplate($template); + } + return is_file($template); + } + /** * 渲染模板文件 * @access public @@ -40,12 +55,8 @@ class Php */ public function fetch($template, $data = []) { - if (!is_file($template)) { - // 获取模板文件名 - $template = $this->parseTemplate($template); - } // 模板不存在 抛出异常 - if (!is_file($template)) { + if (!$this->exists($template)) { throw new Exception('template file not exists:' . $template, 10700); } // 记录视图信息 diff --git a/library/think/view/driver/Think.php b/library/think/view/driver/Think.php index 6867b855..9ee07b26 100644 --- a/library/think/view/driver/Think.php +++ b/library/think/view/driver/Think.php @@ -40,6 +40,21 @@ class Think $this->template = new Template($this->config); } + /** + * 检测是否存在模板文件 + * @access public + * @param string $template 模板文件或者模板规则 + * @return bool + */ + public function exists($template) + { + if (!is_file($template)) { + // 获取模板文件名 + $template = $this->parseTemplate($template); + } + return is_file($template); + } + /** * 渲染模板文件 * @access public @@ -50,12 +65,8 @@ class Think */ public function fetch($template, $data = [], $config = []) { - if (!is_file($template)) { - // 获取模板文件名 - $template = $this->parseTemplate($template); - } // 模板不存在 抛出异常 - if (!is_file($template)) { + if (!$this->exists($template)) { throw new Exception('template file not exists:' . $template, 10700); } // 记录视图信息