2013-08-22 50 views
0

我有以下过滤器:Laravel 4 - 基于模式的过滤器?

Route::filter('security', function() 
{ 
    //do security checks 
    //send to my gateway controller and test() method 

}); 

Route::when('/gateway', 'security'); 

上面似乎没有工作,我要去哪里错了?

  1. 我应该在过滤器中放入什么,以在我的网关控制器中加载我的测试方法?

  2. 如何测试呼叫是使用Ajax调用:

    支持::阿贾克斯()

回答

0

为了让你需要有创建路由/gateway此代码的工作

Route::filter('security', function() 
{ 
    if(Request::ajax()) 
    { 
     //do security checks 
     return Redirect::action('[email protected]'); 
    } 

}); 
Route::when('gateway', 'security'); 
Route::get('/gateway', '[email protected]'); 

注意斜线/Route::when('/gateway', 'security');被删除。 这是因为路由器在根据当前请求的路径信息检查注册模式时添加了斜线