2014-03-06 62 views
0

我正在使用Laravel 4.当在会话中找到“logged_in_id”时,我希望它继续通过波纹管书写的路径进行解析。Laravel重定向问题

Route::get('/{anything}', function($anything) 
{ 
    if(!Session::has('logged_in_id')) { 
     return View::make('user.login'); 
    } else { 
     //continue to check Route::get written bellow this Routing 
    } 
})->where('anything', '[A-Za-z0-9\/?=]+'); 

如果我写Redirect::to('/'.$anything)然后进入同一条路线,并不断在循环重定向。有什么办法可以解决这个问题吗?

+0

则逻辑是错误的。你有没有重定向? – Andreyco

回答

0

我会创建一个过滤器,然后将其应用于任何需要它的路由。

请记住首先放置更具限制性的路线,并使用更通用的路线。

参见例如:

Route::filter('logged_in', function() 
{ 
    if(!Session::has('logged_in_id')) { 
     return View::make('user.login'); 
    } 
}); 

Route::get('testing', array(
    'before' => 'logged_in', 
    function() 
    { 
     return View::make('user.testing'); 
    } 
)); 

Route::get('/{anything}', array(
    'before' => 'logged_in', 

    function($anything) 
    { 
     return View::make('user.anything'); 
    } 

))->where('anything', '[A-Za-z0-9\/?=]+');