2013-03-14 48 views
0

我在Stack上搜索並查看這個問題How to add filter parameters to controllers in Laravel?帶參數的Laravel濾波器

我有一個類似的問題,但這個時候,我需要通過一個靈活的$ myparam的說法,代碼看起來像波紋管:

在Route.php

Route::filter('diffauthor',function($myparam){ 
    if(Authority::cannot('edit', 'postedit', $myparam)) 
         return View::make('permdeny.index'); 
}); 

和控制器:

public function __construct() { 
     parent::__construct(); 
     $this->filter('before','diffauthor', $myparam); 
    } 

如何通過$ myparam基於用戶請求?

回答

3

只能將參數傳遞給過濾器的字符串:

$this->filter('before', 'diffauthor:param1,param2'); 

有時爲了繞過這個限制我使用Session類作爲一種臨時存儲,甚至檢查正在傳遞給方法變量通過查看我的過濾器中的Request::route()返回的對象。