写一个class类在类中写一个ob缓存的方法,下面查询出来的数据$data(是你自己要查的数据,不是必须$this->sel()这样写)。$data这个变量在content.php做的是循环变量。 使用时实例化类调用这个ob方法就可以使用了
如果你懂php相信你会看懂的。。。
在tp5中的写法
<?php
class cache{
public function ob(){
//开启缓存
ob_start();
//查询的数据
$data= $this->sel();
//调用的模板位置
$file = "content.php";
include ($file);
//清除
$content = ob_get_clean();
//生成的静态页位置 type是文件夹的名字
$last = "./type/$id.html";
file_put_contents($last,$content);
}
}
content.php的代码(要调用的模板的)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1">
<tr>
<td>标题</td>
<td>内容</td>
</tr>
<tr>
<td><?php echo $data['title']?></td>
<td><?php echo $data['content']?></td>
</tr>
</table>
</body>
</html>
在laravel框架中的写法
在控制器中写的方法
//生成静态页
public function jt($id){
ob_start();
$arr =$res=Zc::article_sel($id);
//模板位置
$file_dir=base_path()."/resources/views/zc/muban.blade.php";
include ($file_dir);
if(!file_exists("storage/html")){
mkdir("storage/html");
}
//静态页生成的位置
$html_dir="storage/html/$id.html";
file_put_contents($html_dir,ob_get_clean());
//跳转到静态页
echo "<script>location.href='http://www.lr.com/storage/html/$id.html'</script>";
}