function staticIndex() { $content = $smarty->fetch('index.html',true);//这是Smarty自带的生成静态页面的函数 $static_name = ROOT_PATH.'index.html';//这是生成静态页面当前的路径文件 fopen($static_name,'a');//打开这个文件 @file_put_contents($static_name,$content);//最后写进去 return true; } //静态化列表页,按类别不同经行静态化 function staticContent(){//需要静态话的条数 $ids = array();//获取所有的内容 $ids = $this->getListIds();//这个方法获取所有的内容,下面红字部分对应它的方法 foreach($ids as $k=>$value){ //echo $value['catid']; if(!file_exists(ROOT_PATH.'demo/')){//判断根目录下面有没有这个文件夹,如果没有则创建demo这个文件夹 mkdir(ROOT_PATH.'demo/'); } if(!file_exists(ROOT_PATH.'demo/'.$value['catid'])){//判断这个文件夹下面有没有对应的类别文件夹 mkdir(ROOT_PATH.'demo/'.$value['catid']); } $html_content = $this->getDemoContent($value['demoid']); $static_name = ROOT_PATH.'demo/'.$value['catid'].'/'.$value['demoid'].'.html'; fopen($static_name,'a'); @file_put_contents($static_name,$html_content); } return true; } //拿出需要静态化的页面ID function getListIds(){ $sql = "select * from {$this->tablepre}demo order by demoid asc"; $rs = $this->db->getAll($sql); if($rs){ return $rs; }else{ return false; } } //content单页静态化 function getDemoContent($id){ global $smarty,$view_templates,$admin_templates; loadModel(array('demo')); $demo = new demo(); $content = ''; $smarty->template_dir = ROOT_PATH.$view_templates; $getMobanOne = $this->getMobanDetail($id); $mobandetail = $demo->MobanList($id); foreach($mobandetail as $k=>$v){ $smarty->assign($k,$v); } $this->catid = $getMobanOne['catid']; $smarty->assign('pre_title',$mobandetail['membername']); $smarty->assign('mobandetail',$mobandetail); $content = $smarty->fetch('demo_show.html',true); $smarty->template_dir = ROOT_PATH.$view_templates; return $content; }