我正在使用Laravel4.1。
我希望在不同的过滤器和相同的Object中进行相同的处理,如下所示。
Route::filter('filter1', function(){
$sameObject = // I want to fetch sameObject;
View::share('obj', $sameObject);
});
Route::filter('filter2', function(){
$sameObject = // I want to fetch sameObject;
if(isset($sameObject){
return Redirect::to('home')
}
});
有没有办法让DRY过程?
答案 0 :(得分:1)
尝试使用session或config(gimmick)方法:
Route::filter('filter1', function(){
$sameObject = // I want to fetch sameObject;
Config::set('myObject',$sameObject);
View::share('obj', $sameObject);
});
Route::filter('filter2', function(){
$sameObject = Config::get('myObject');
if(isset($sameObject){
return Redirect::to('home')
}
});