1.laravel页面静态化的方法
public function info(Request $request){
$id=$request->get('id');
$dir = dirname(app_path()).'/resources/views/html';
if(file_exists($dir.'/list_'.$id.'.blade.php')){
echo '纯静态页面';
return view('html.list_'.$id);
}
$data=Article::where('id',$id)->first();//查询数据
$content = view('tenthree.info',compact('data'));//渲染模板
if(!file_exists($dir)){
mkdir($dir);
}
file_put_contents($dir.'/list_'.$id.'.blade.php',$content);
return $content;
}
2.另一种也可以
public function info(Request $request){
$id=$request->id;
$filename='./info/'.$id.'.php';
if (file_exists($filename)){
return view()->file($filename);
}else{
$data=MessModel::info($id);
$html=view('info',compact('data'));
file_put_contents($filename,$html);
return $html;
}
}