5.0.0 - 普通 - 未处理
昨天我提了个问题是可以在程序中自定义设置模板路径的问题。今天看了。大神们分别在view,模板引擎(think,php)中都加了config方法,
但还是没有解决问题啊。。加这两个config,都指向了最终的template的config
但是在模板引擎中
protected $config = [
// 模板起始路径
'view_path' => '',
// 模板文件后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DS,
// 是否开启模板编译缓存,设为false则每次都会重新编译
'tpl_cache' => true,
];
这四个参数和template中的相同的四个参数是不同步的,
也就是说假如我通过config设置了view_path=c:\
那么在模板中使用include 的时候,相对应的路径改变了,
但是通过控制器$this->fetch(),所读取的模板路径却没有跟着改变
解决方案:
模板引擎(view/driver下的think和php两个文件)
把方法
public function config($name, $value = null)
{
if (is_array($name)) {
$this->template->config($name);
} else {
$this->template->$name = $value;
}
}
改为
public function config($name, $value = null)
{
if (is_array($name)) {
$this->config = array_merge($this->config, $name);
$this->template->config($name);
} else {
$this->template->$name = $value;
$this->config[$name] = $value;
}
}
