基类中的生成前与生成后的方法
class Common extends BaseController
{
//静态模板生成目录
protected $staticHtmlDir = "";
//静态文件
protected $staticHtmlFile = "";
//判断是否存在静态
public function beforeBuild($param = []) {
//生成静态
$this->staticHtmlDir = "html".DS.$this->request->controller().DS;
//参数md5
$param = md5(json_encode($param));
$this->staticHtmlFile = $this->staticHtmlDir .$this->request->action() . '_' . $param .'.html';
//目录不存在,则创建
if(!file_exists($this->staticHtmlDir)){
mkdir($this->staticHtmlDir);
}
//静态文件存在,并且没有过期
if(file_exists($this->staticHtmlFile) && filectime($this->staticHtmlFile)>=time()-60*60*24*5) {
header("Location:/" . $this->staticHtmlFile);
exit();
}
}
//开始生成静态文件
public function afterBuild($html) {
if(!empty($this->staticHtmlFile) && !empty($html)) {
if(file_exists($this->staticHtmlFile)) {
\unlink($this->staticHtmlFile);
}
if(file_put_contents($this->staticHtmlFile,$html)) {
header("Location:/" . $this->staticHtmlFile);
exit();
}
}
}
}
控制器中的使用
public function getList($id = '')
{
//判断静态界面是否存在
$this->beforeBuild(array($id));
// do someing
$name = "测试静态化";
$html = View::fetch('/get_list',['name'=>$name]);
//生成静态界面
$this->afterBuild($html);
}
THE END
匿名
2025-10-22
盖楼盖楼!
匿名
2025-08-11
沙发沙发
匿名
2025-08-10
https://at.oiik.cn/bing.html
匿名
2025-02-21
实用,我在开发https://minmail.app/时候使用到了
王飞翔
2024-12-30
亲爱的朋友:您好!中国疫情持续蔓延,很多人症状非常严重持久不愈,医院人满为患,各年龄段随地倒猝死的现象暴增,多省感染手足口、甲流、乙流、支原体、合胞及腺病毒的儿童不断攀升,目前各种天灾人祸,天气异象频发。古今中外的很多预言都说了这几年人类有大灾难,如刘伯温在预言中说 “贫者一万留一千,富者一万留二三”,“贫富若不回心转,看看死期到眼前”, 预言中也告诉世人如何逃离劫难的方法,真心希望您能躲过末劫中的劫难,有个美好的未来,请您务必打开下方网址认真了解,内有躲避瘟疫保平安的方法。网址1:https://github.com/1992513/www/blob/master/README.md?abhgc#1 网址2:bitly.net/55bbbb 网址3:https://d3ankibxiji86m.cloudfront.net/30gj 如打不开请多换几个浏览器试
匿名
2024-12-12
Backdata 搜索引擎网址提交入口:https://backdata.net/submit-site.html