【问题标题】:Laravel 4 - Pattern Based Filter?Laravel 4 - 基于模式的过滤器?
【发布时间】:2013-10-13 03:05:47
【问题描述】:

我有以下过滤器:

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

});

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

上面的好像不行,我哪里错了?

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

  2. 如何测试调用是否为 ajax 调用:

    请求::ajax()

【问题讨论】:

    标签: laravel laravel-4


    【解决方案1】:

    为了使此代码正常工作,您需要创建一个路由 /gateway

    Route::filter('security', function()
    {
        if(Request::ajax()) 
        {
            //do security checks
            return Redirect::action('GatewayController@test');
        }
    
    });
    Route::when('gateway', 'security');
    Route::get('/gateway', 'GatewayController@test');
    

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

    【讨论】:

      猜你喜欢
      • 2013-10-28
      • 2013-06-01
      • 2021-08-30
      • 2014-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      相关资源
      最近更新 更多