改进Php模板引擎驱动的模板定位规则

This commit is contained in:
thinkphp
2016-12-08 11:04:39 +08:00
parent 89239cceb4
commit 501cc85207
2 changed files with 17 additions and 7 deletions

View File

@@ -115,7 +115,9 @@ return [
'template' => [
// 模板引擎类型 支持 php think 支持扩展
'type' => 'Think',
// 模板路径
// 视图基础目录,配置目录为所有模块的视图起始目录
'view_base' => '',
// 当前模板的视图目录 留空为自动获取
'view_path' => '',
// 模板后缀
'view_suffix' => 'html',

View File

@@ -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) {
// 如果模板文件名为空 按照默认规则定位