改进模板引擎类parseTemplateFile方法

This commit is contained in:
thinkphp
2016-12-02 22:14:57 +08:00
parent 2061588c49
commit 65f13177c2

View File

@@ -12,6 +12,7 @@
namespace think; namespace think;
use think\exception\TemplateNotFoundException; use think\exception\TemplateNotFoundException;
use think\Request;
/** /**
* ThinkPHP分离出来的模板引擎 * ThinkPHP分离出来的模板引擎
@@ -1061,14 +1062,18 @@ class Template
{ {
if ('' == pathinfo($template, PATHINFO_EXTENSION)) { if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
if (strpos($template, '@')) { if (strpos($template, '@')) {
// 跨模块调用模板 list($module, $template) = explode('@', $template);
$template = str_replace(['/', ':'], $this->config['view_depr'], $template);
$template = APP_PATH . str_replace('@', '/' . basename($this->config['view_path']) . '/', $template);
} else {
$template = str_replace(['/', ':'], $this->config['view_depr'], $template);
$template = $this->config['view_path'] . $template;
} }
$template .= '.' . ltrim($this->config['view_suffix'], '.'); if (0 !== strpos($template, '/')) {
$template = str_replace(['/', ':'], $this->config['view_depr'], $template);
}
if ($this->config['view_base']) {
$module = isset($module) ? $module : Request::instance()->module();
$path = $this->config['view_base'] . ($module ? $module . DS : '');
} else {
$path = $this->config['view_path'];
}
$template = $path . $template . '.' . ltrim($this->config['view_suffix'], '.');
} }
if (is_file($template)) { if (is_file($template)) {