1, ); $obj=new \Home\Controller\IndexController(); $content=$obj->index(); $htmlfile="./".C("setting.indexFileName"); self::saveFile($htmlfile,$content); } //生成栏目页 public function listHtml($catid,$p,$classpath){ $_GET=array( "catid"=>$catid, "p"=>$p, "isSystemMakeHtml"=>1, ); $obj=new \Home\Controller\ListController(); $content=$obj->index(); $filename=$p>1?("index_".$p.".html"):"index.html"; $htmlfile=".".$classpath.$filename; self::saveFile($htmlfile,$content); } //生成自定义页 public function pageHtml($page_id,$classpath){ //如果通过在Admin模块生成的,一定要用url方式获取,否则在模板里里如果调用Home模块下的函数的话,在后台生成会报错 if(MODULE_NAME=="Admin"){ $url = 'http://'.$_SERVER['HTTP_HOST'].U('Home/Page/index',array("page_id"=>$page_id)); $content = @file_get_contents($url); }else{ $_GET=array( "page_id"=>$page_id, "isSystemMakeHtml"=>1, ); $obj=new \Home\Controller\PageController(); $content=$obj->index(); } $htmlfile=".".$classpath; self::saveFile($htmlfile,$content); } //生成自定义列表页 public function pagesHtml($pages_id,$p,$classpath){ $_GET=array( "pages_id"=>$pages_id, "p"=>$p, "isSystemMakeHtml"=>1, ); $obj=new \Home\Controller\PagesController(); $content=$obj->index(); $filename=$p>1?("index_".$p.".html"):"index.html"; $htmlfile=".".$classpath.$filename; self::saveFile($htmlfile,$content); } //生成内容页 public function detailHtml($catid,$id,$classpath){ if(MODULE_NAME=="Admin"){ $url = 'http://'.$_SERVER['HTTP_HOST'].U('Home/View/index',array("catid"=>$catid,"id"=>$id)); $content = @file_get_contents($url); }else{ $_GET=array( "catid"=>$catid, "id"=>$id, "isSystemMakeHtml"=>1, ); $obj=new \Home\Controller\ViewController(); $content=$obj->index(); } $filename=$id.".html"; $htmlfile=".".$classpath.$filename; self::saveFile($htmlfile,$content); } //获取指定文件夹下文件数量 public function fileNum($path){ $flag = \FilesystemIterator::KEY_AS_FILENAME; $glob = new \FilesystemIterator($path, $flag); $i=0; foreach ($glob as $name => $file) { // $i++; } return $i; } //写入文件 public function saveFile($filePath,$content){ \Think\Storage::put($filePath,$content,'html'); $fp = fopen($filePath,"w"); fwrite($fp,$content); fclose($fp); } // }