码迷,mamicode.com
首页 > 其他好文 > 详细

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

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

标签:静态化   xxx   lang   文件路径   art   ora   生成静态化   tar   pre   

// 获取渲染后的视图内容
$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方法

标签:静态化   xxx   lang   文件路径   art   ora   生成静态化   tar   pre   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!