Php 如何发送url';s参数,然后在那里检索它?

Php 如何发送url';s参数,然后在那里检索它?,php,laravel-4,laravel-routing,Php,Laravel 4,Laravel Routing,如何将url的参数发送到filter.php并在那里检索它 路线 我想将{id}从上面的URL发送到filter.php并在那里检索它的值 像这样的 Route::filter('access', function($id) { if (Auth::check()) { if (Auth::user()->is_admin != 1 && Auth::user()->id = $id) {

如何将url的参数发送到filter.php并在那里检索它

路线

我想将{id}从上面的URL发送到filter.php并在那里检索它的值

像这样的

Route::filter('access', function($id)
    {
        if (Auth::check())
        {
            if (Auth::user()->is_admin != 1 && Auth::user()->id = $id) {
                return View::make('users.noaccess');
            }
        }
        else
        {
            return Redirect::guest('/')->with('error', 'Please login to access this page');
        }
    });
然后使用beforeFilter将筛选器绑定到方法

$this->beforeFilter('access', array('only' => 'edit'));

filter closure函数接受多个参数()。您可以像这样重写过滤器:

Route::filter('access', function($route) {
   $id = $route->parameter('id');
   if (Auth::check()) {
        if (Auth::user()->is_admin != 1 && Auth::user()->id = $id) {
            return View::make('users.noaccess');
        }
   } else {
        return Redirect::guest('/')->with('error', 'Please login to access this page');
   }
});

谢谢你,卡肯!在我第一次尝试时,它不起作用,但我只是注意到问题出在我的问题上。确切的路由不是
route::get('/users/{id}/edit','UsersController@edit');
but
Route::get('/users/{users}/edit','UsersController@edit');
因此更改了
$id=$route->参数('id')
$id=$route->参数('users')
Route::filter('access', function($route) {
   $id = $route->parameter('id');
   if (Auth::check()) {
        if (Auth::user()->is_admin != 1 && Auth::user()->id = $id) {
            return View::make('users.noaccess');
        }
   } else {
        return Redirect::guest('/')->with('error', 'Please login to access this page');
   }
});