From ff8f2080d2c66e853348e2326e7a1251646c4998 Mon Sep 17 00:00:00 2001 From: augushong Date: Mon, 21 Oct 2024 16:44:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E5=9B=BE=E5=B1=82=E5=A2=9E=E5=8A=A0./?= =?UTF-8?q?=E7=9A=84include=E7=9A=84=E5=BC=95=E5=85=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/think/Template.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extend/think/Template.php b/extend/think/Template.php index 38f0d7f..4bb4174 100644 --- a/extend/think/Template.php +++ b/extend/think/Template.php @@ -93,6 +93,8 @@ class Template */ protected ?CacheInterface $cache; + private string $fetchFile; + /** * 架构函数. * @param array $config @@ -226,6 +228,7 @@ class Template $template = $this->parseTemplateFile($template); if ($template) { + $this->fetchFile = $template; $cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($this->config['layout_on'] . $this->config['layout_name'] . $template) . '.' . ltrim($this->config['cache_suffix'], '.'); if (!$this->checkCache($cacheFile)) { @@ -1194,7 +1197,6 @@ class Template } else { $template = str_replace(['/', ':'], $this->config['view_depr'], substr($template, 1)); } - if (str_starts_with($template, '@' . DIRECTORY_SEPARATOR)) { // 以@/开头,则从框架跟目录定位 $app_path = $this->getConfig('view_root_path'); @@ -1209,6 +1211,10 @@ class Template $view_app_path = $this->getConfig('base_view_path'); $template = str_replace('@', '', $template); + } elseif (str_starts_with($template, '.' . DIRECTORY_SEPARATOR)) { + $dirname = dirname($this->fetchFile); + $template = $dirname . ltrim($template, '.') . '.' . ltrim($this->config['view_suffix'], '.'); + goto TEMPLATE_PARSED; } else { $app_path = $this->getConfig('app_path'); $base_app_path = $this->getConfig('base_app_path'); @@ -1230,7 +1236,7 @@ class Template $template = $template_file_path; } - + TEMPLATE_PARSED: if (is_file($template)) { // 记录模板文件的更新时间 $this->includeFile[$template] = filemtime($template);