首页 > 其他 > 详细

Laravel blade模板生成静态化file_put_contents方法

时间:2020-05-19 18:54:59      阅读:67      评论:0      收藏:0      [点我收藏+]

// 获取渲染后的视图内容
$view = view(‘index‘, compact(‘data‘))->__toString();
// 使用PHP内置方法 file_put_contents()生成静态页面
file_put_contents("index.html", $view);

生成的文件路径为 public/index.html

详细

$view = view(‘index‘)->with(‘data‘,‘xxx‘);
$html = response($view)->getContent();
if (file_exists(storage_path() .‘/demo/1.html‘)) {
        return response()->file(storage_path() ."/demo/1.html");
}
if (! file_exists(storage_path() .‘/demo‘)) {
        mkdir(storage_path() .‘/demo‘);
}
file_put_contents(storage_path() ."/demo/".‘1.html‘,$html);
chmod(storage_path() ."/demo/‘1.html", ‘0777‘);
return response()->file(storage_path() ."/demo/1.html");

 

Laravel blade模板生成静态化file_put_contents方法

原文:https://www.cnblogs.com/pxuan/p/12918225.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!