php 生成静态页面

本人用的thinkcmf 基于tp5 

首先引入一下类:use think emplatedriverFile;

下面是公共方法:

function mackHtml($content = '',$path='',$pcorwap=1){
    $File = new File;
    $File->fwrite($path.'/index.html', $content);
    $dir = $pcorwap == 1 ? 'public/' : 'm/';//这里事做了一下判断 1:PC端  2:移动端
    $path = $path == '.' ? $dir.'index.html' : $dir.$path;//在当前的根目录下生成文件及页面
    $ishave = Db::name('html')->where(['path'=>$path])->find();//查询数据库里是否存在
    if(!$ishave){//不存在则直接入库并记录
        Db::name('html')->insert(['path'=>$path,'time'=>date('Y-m-d H:i:s',time())]);
    }
}

  控制器调用:

这里拿首页进行展示,参数一是渲染的页面,参数二是目录,参数三默认是1 
mackHtml($this->fetch(':index'),'.');