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; }