tp5里模版引用其它文件时view_path无效,详见如下:
//index.html
//文件位置:[ VIEW ] D:\servers\htdocs\think-5.0-rc2\public\tmp\index\index.html [ array ( 'name' => 'thinkphp', ) ]
{include file="index@view/index/public/abc/def/g" /}
//文件位置:D:/servers/htdocs/think-5.0-rc2/application/index/view/index/public/abc/def/g.html
//这是可以正常识别
{include file="index/public/abc/def/g" /}
//文件位置:D:/servers/htdocs/think-5.0-rc2/public/tmp/index/public/abc/def/g.html
//这句不能识别,因为template->parseTemplateFile()中的$this->config['view_path']为空引起错误.
//https://github.com/top-think/think/blob/master/thinkphp/library/think/Template.php#L1017
{include file="abc" /}
//这样正常.
...
//index.php
namespace app\index\controller;
class Index
{
public function index()
{
$view = new \think\View([
'view_path' => realpath('./tmp'),
'view_suffix' => '.html',
'view_depr' => DS,
'view_layer' => VIEW_LAYER,
'parse_str' => [],
'engine_type' => 'think',
]);
// 渲染模板输出 并赋值模板变量
return $view->config('view_path','./tmp')->fetch('index', ['name' => 'thinkphp']);
}
}
https://github.com/top-think/think/blob/master/thinkphp/library/think/Template.php#L1017
这里的(defined('THEME_PATH') && substr_count($template, '/') < 2 ? THEME_PATH : $this->config['view_path']);条件我不清楚你们有什么用意但是
$this->config['view_path']
中永远为空.所以返回的路径不是绝对路径.从而导致parseTemplateName不能得到文件内容.
希望能找到**$this->config['view_path']**总为空的原因.
另外最新的git,也同样有这个问题.