From 501cc852077fa21b7e97d2dc581fb2770a6d212a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 8 Dec 2016 11:04:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BPhp=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E9=A9=B1=E5=8A=A8=E7=9A=84=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 4 +++- library/think/view/driver/Php.php | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/convention.php b/convention.php index 8eb30f43..487c2481 100644 --- a/convention.php +++ b/convention.php @@ -115,7 +115,9 @@ return [ 'template' => [ // 模板引擎类型 支持 php think 支持扩展 'type' => 'Think', - // 模板路径 + // 视图基础目录,配置目录为所有模块的视图起始目录 + 'view_base' => '', + // 当前模板的视图目录 留空为自动获取 'view_path' => '', // 模板后缀 'view_suffix' => 'html', diff --git a/library/think/view/driver/Php.php b/library/think/view/driver/Php.php index 4f3d7e85..863a7c17 100644 --- a/library/think/view/driver/Php.php +++ b/library/think/view/driver/Php.php @@ -21,6 +21,8 @@ class Php { // 模板引擎参数 protected $config = [ + // 视图基础目录(集中式) + 'view_base' => '', // 模板起始路径 'view_path' => '', // 模板文件后缀 @@ -109,20 +111,26 @@ class Php $this->config['view_path'] = App::$modulePath . 'view' . DS; } + $request = Request::instance(); + // 获取视图根目录 if (strpos($template, '@')) { + // 跨模块调用 list($module, $template) = explode('@', $template); - $path = APP_PATH . $module . DS . 'view' . DS; + } + if ($this->config['view_base']) { + // 基础视图目录 + $module = isset($module) ? $module : $request->module(); + $path = $this->config['view_base'] . ($module ? $module . DS : ''); } else { - $path = $this->config['view_path']; + $path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : $this->config['view_path']; } - // 分析模板文件规则 - $request = Request::instance(); - $controller = Loader::parseName($request->controller()); - $depr = $this->config['view_depr']; + $depr = $this->config['view_depr']; if (0 !== strpos($template, '/')) { $template = str_replace(['/', ':'], $depr, $template); } + + $controller = Loader::parseName($request->controller()); if ($controller) { if ('' == $template) { // 如果模板文件名为空 按照默认规则定位