From 4b1e88d0cbc5429423a3598525fd3566ed92c226 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 26 Apr 2016 17:39:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BView=E7=B1=BBengine=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E5=A6=82=E6=9E=9C=E4=BC=A0=E5=85=A5=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=20=E5=88=99=E8=A1=A8=E7=A4=BA=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=BC=95=E6=93=8E=E5=90=8D=E7=A7=B0=20=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=BC=95=E6=93=8E=E5=8F=82=E6=95=B0=E5=8F=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=20=E5=A2=9E=E5=8A=A0=20view=5Freplace=5Fstr?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=20=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=85=A8=E5=B1=80=20=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=86=85=E5=AE=B9=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 2 ++ library/think/Controller.php | 2 +- library/think/View.php | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/convention.php b/convention.php index 4f74f7f9..3fe6ed1f 100644 --- a/convention.php +++ b/convention.php @@ -117,6 +117,8 @@ return [ 'taglib_end' => '}', ], + // 视图输出字符串内容替换 + 'view_replace_str' => [], // 默认跳转页面对应的模板文件 'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', 'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', diff --git a/library/think/Controller.php b/library/think/Controller.php index 618d67f7..d43c8727 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -35,7 +35,7 @@ class Controller */ public function __construct() { - $this->view = View::instance(Config::get('template')); + $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); // 控制器初始化 if (method_exists($this, '_initialize')) { diff --git a/library/think/View.php b/library/think/View.php index aa89b0bf..2ca2807d 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -70,14 +70,22 @@ class View /** * 设置当前模板解析的引擎 * @access public - * @param array $options 引擎参数 + * @param array|string $options 引擎参数 * @return $this */ public function engine($options = []) { - $type = !empty($options['type']) ? $options['type'] : 'Think'; + if (is_string($options)) { + $type = $options; + $options = []; + } else { + $type = !empty($options['type']) ? $options['type'] : 'Think'; + } + $class = (!empty($options['namespace']) ? $options['namespace'] : '\\think\\view\\driver\\') . ucfirst($type); - unset($options['type']); + if (isset($options['type'])) { + unset($options['type']); + } $this->engine = new $class($options); return $this; }