利用\think\template\driver\File.php文件整合buildHtml
1.在controller.php创建方法如下
/**
- 创建静态页面
- @access protected
- @htmlfile 生成的静态文件名称
- @htmlpath 生成的静态文件路径
- @param string $templateFile 指定要调用的模板文件
- 默认为空 由系统自动定位模板文件
- @return string
*/
protected function buildHtml($htmlfile = ‘’, $htmlpath = ‘’, $templateFile = ‘’)
{
$content =
t
h
i
s
−
>
f
e
t
c
h
(
this->fetch(
this−>fetch(templateFile);
h
t
m
l
p
a
t
h
=
!
e
m
p
t
y
(
htmlpath = !empty(
htmlpath=!empty(htmlpath) ? $htmlpath : ‘./appTemplate/’;
$htmlfile = $htmlpath . $htmlfile . ‘.’.config(‘url_html_suffix’);
$File = new \think\template\driver\File();
F
i
l
e
−
>
w
r
i
t
e
(
File->write(
File−>write(htmlfile, $content);
return $content;
}
2.需要用到的地方直接调用
t
h
i
s
−
>
b
u
i
l
d
H
t
m
l
(
this->buildHtml(
this−>buildHtml(id,APP_PATH.‘app/view/content/’,APP_PATH.‘app/tpl/activity.html’);
$this->buildHtml(‘index’,APP_PATH.’…/resource/index/’,‘index’);