tp5 File文件写入(生成静态文件)

匿名 (未验证) 提交于 2019-12-03 00:27:02
利用\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 = $this->fetch($templateFile);
$htmlpath = !empty($htmlpath) ? $htmlpath : './appTemplate/';
$htmlfile = $htmlpath . $htmlfile . '.'.config('url_html_suffix');

$File = new \think\template\driver\File();
$File->write($htmlfile, $content);
return $content;
}

2.需要用到的地方直接调用
$this->buildHtml($id,APP_PATH.'app/view/content/',APP_PATH.'app/tpl/activity.html');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!