加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Laravel:View :: share()和View :: composer()之间的区

发布时间:2020-12-14 19:46:08 所属栏目:大数据 来源:网络整理
导读:关于问题 Passing default variables to view,要传递所有视图中可用的变量,使用View :: composer()之间是否存在技术或功能差异: View::composer('*',function($view) { $thundercats = 'Woooooohh!!'; $view-with('thundercats',$thundercats);}) 在filters
关于问题 Passing default variables to view,要传递所有视图中可用的变量,使用View :: composer()之间是否存在技术或功能差异:
View::composer('*',function($view) {
    $thundercats = 'Woooooohh!!';
    $view->with('thundercats',$thundercats);
})

在filters.php文件中或在BaseController.php文件中使用View :: share():

public function __construct {
    $thundercats = 'Woooooohh!!';
    View::share('thundercats',$thundercats);
}

我最近才了解到View :: share()并发现它非常有侵略性,尽管我已经开始在另一个项目中使用前者了.

编辑:

我的第一个假设是前者是一个文件(filters.php),而后者是一个类(BaseController.php).考虑到这一点,我猜一个班级好多了?虽然,我现在还不太清楚为什么.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读