首先先要把需要静态化的内容填充到模版中去
复制代码 代码如下:
#eg.这个是静态化首页的
function staticIndex(){
$newslist = $article->getArticles(null,54,'DESC',1,6,false,1,2,'',0,0,1);
if($newslist){
foreach($newslist as $k=>$v){
$newslist[$k]['title_all'] = $v['title'];
$newslist[$k]['title'] = cutstr($v['title'],36,'…');
}
$smarty->assign('newslist',$newslist);
}
$content = '';
$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;
}
以前用的那个生成静态页面每次都要执行PHP文件,然后才能生成,现在我写的这个就是由人控制的,想生成就生成,很方便,希望能给大家带来方便,祝大家工作愉快。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment