【发布时间】:2013-08-21 08:52:26
【问题描述】:
关于问题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)。考虑到这一点,我猜一堂课要好得多?虽然,我不太清楚为什么在这一点上。 :)
【问题讨论】: