Laravel 4 筛选器之前失败时,不会取消筛选器之后的路由

Laravel 4 筛选器之前失败时,不会取消筛选器之后的路由,laravel-4,laravel-routing,Laravel 4,Laravel Routing,根据,当路由的前过滤器失败时,后过滤器被取消,但情况似乎并非如此。我正在从数据库中提取导航。“过滤前的我的路线”无论是在route::group还是普通路线上,都会检查某个人是否访问过某个页面。如果没有,它将返回重定向::路由(“新路由”) 过滤后的路由将向已访问的页面表中添加一行 当我点击一个我还没有访问过它的先决条件页面的链接时,它会重定向。但是-它仍然会向数据库中添加一行。所以赛后比赛没有被取消。它还在开火 我测试这个的方式是我已经登录并在一个页面上。已从数据库中清除页面访问。然后我点击了

根据,当路由的前过滤器失败时,后过滤器被取消,但情况似乎并非如此。我正在从数据库中提取导航。“过滤前的我的路线”无论是在route::group还是普通路线上,都会检查某个人是否访问过某个页面。如果没有,它将返回重定向::路由(“新路由”)

过滤后的路由将向已访问的页面表中添加一行

当我点击一个我还没有访问过它的先决条件页面的链接时,它会重定向。但是-它仍然会向数据库中添加一行。所以赛后比赛没有被取消。它还在开火

我测试这个的方式是我已经登录并在一个页面上。已从数据库中清除页面访问。然后我点击了我的“教室”导航项。这需要“定位”

进入数据库的是按以下顺序进行的页面访问:

  • 教室
  • 课堂教学
  • 定向
  • 我希望看到的是:

  • 定向
  • 路线

    Route::group(array("prefix"=>"classroom","before"=>"checkPrerequisite"),function()
    {
        Route::get('/',array(
            'as'=>'classroom',
            'uses'=>'ClassroomController@index',
            'after'=>'addvisit',
            ));
        //there are more routes here, but they don't need after filters.
        Route::get('/instructions',array(
            'as'=>'classroom.instructions',
            'after'=>'addvisit',
            function()
            {
                return View::make('classroom.instructions');
            }
        ));
    });
    
    筛选前

        Route::filter('checkPrerequisite', function($route, $request)
    {
        $sPrerequisite = Navigation::where('url','=',Navigation::where('url','=',Route::currentRouteName())->first()->prerequisite)->first();
        // get the module id from session
        $mod_id = Session::get('current_module');
        // get the page from the user_page_visits
        $page = Auth::user()
                        ->pages()
                        ->where('module_id','=',$mod_id)
                        ->where('nav_id','=',$sPrerequisite->id)
                        ->first();
    
        if(!$page) return Redirect::route($sPrerequisite->url);
    });
    
    Route::filter('addvisit', function($route, $request, $response)
    {
        // get the current route
        $current = Route::currentRouteName();
        // get the id of the navigation item with this route
        $nav_id = Navigation::where('url','=',$current)->first()->id;
        // get the module id from cache
        $mod_id = Session::get('current_module');
        // see if the page has been visited
        $page = Auth::user()
                        ->pages()
                        ->where('module_id','=',$mod_id)
                        ->where('nav_id','=',$nav_id)
                        ->first();
    
        if($page)
        {
            // if it has been visited, increment the visits column by 1
            $page->increment('visits');
        }
        else
        {
            // otherwise, create a new page visit
            $visit = new UserPageVisits;
            $visit->user_id = Auth::user()->id;
            $visit->module_id = $mod_id;
            $visit->nav_id = $nav_id;
            $visit->save();
        }
    });
    
    过滤后

        Route::filter('checkPrerequisite', function($route, $request)
    {
        $sPrerequisite = Navigation::where('url','=',Navigation::where('url','=',Route::currentRouteName())->first()->prerequisite)->first();
        // get the module id from session
        $mod_id = Session::get('current_module');
        // get the page from the user_page_visits
        $page = Auth::user()
                        ->pages()
                        ->where('module_id','=',$mod_id)
                        ->where('nav_id','=',$sPrerequisite->id)
                        ->first();
    
        if(!$page) return Redirect::route($sPrerequisite->url);
    });
    
    Route::filter('addvisit', function($route, $request, $response)
    {
        // get the current route
        $current = Route::currentRouteName();
        // get the id of the navigation item with this route
        $nav_id = Navigation::where('url','=',$current)->first()->id;
        // get the module id from cache
        $mod_id = Session::get('current_module');
        // see if the page has been visited
        $page = Auth::user()
                        ->pages()
                        ->where('module_id','=',$mod_id)
                        ->where('nav_id','=',$nav_id)
                        ->first();
    
        if($page)
        {
            // if it has been visited, increment the visits column by 1
            $page->increment('visits');
        }
        else
        {
            // otherwise, create a new page visit
            $visit = new UserPageVisits;
            $visit->user_id = Auth::user()->id;
            $visit->module_id = $mod_id;
            $visit->nav_id = $nav_id;
            $visit->save();
        }
    });
    

    在您发布的路线中甚至没有
    addvisit
    过滤器。我假设这就是代码打开的情况?正确-这就是代码打开的情况。我已经更新了。对不起:)相关: