laravel3 framework 在controller 內的redirect

在controller裡面,只有action_xxx的function內才有辦法使用redirect… 那如果你想在其它種類的function內使用redirect,就得用filter的方式去處理

先在Route.php內建立一個filter

Route::filter('bye',function(){
Session::flush();
return Redirect::to('/');
});

然後在你的controller內寫上你的filter

if($a!=$b){
    $this->filter('before','bye');
}

存檔即可… 這是唯一的解法,也可以用在construct裡面的唯一可用的方式 更詳細的請看 http://laravel.com/docs/controllers#action-filters

發佈留言