tp5 File文件寫入(生成靜態文件)

利用\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(this->fetch(templateFile);
htmlpath=!empty(htmlpath = !empty(htmlpath) ? $htmlpath : ‘./appTemplate/’;
$htmlfile = $htmlpath . $htmlfile . ‘.’.config(‘url_html_suffix’);

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

2.需要用到的地方直接調用
this>buildHtml(this->buildHtml(id,APP_PATH.‘app/view/content/’,APP_PATH.‘app/tpl/activity.html’);

$this->buildHtml(‘index’,APP_PATH.’…/resource/index/’,‘index’);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章