【问题标题】:Limit pagination Laravel 4 when page not exist当页面不存在时限制分页 Laravel 4
【发布时间】:2014-03-12 08:49:41
【问题描述】:

我有这个代码:

    public function test(){
    $results = Cand::paginate(4);

    if (Request::ajax()) {
         return Response::json(View::make('admin.posts')->with('results', $results)->render());
    }

    $this->layout->content = View::make('admin.dashboard')->with('results', $results);
 }

它可以正常工作,但是当用户输入 URL 中不存在的页面时,例如“?page=9999”,我该如何限制呢?

【问题讨论】:

    标签: php laravel pagination laravel-4


    【解决方案1】:

    您可以通过在分页器实例上调用 getLastPage() 来获取最后一页:

    if ( Input::get('page', 1) > $results->getLastPage() )
    {
        App::abort(404);
    }
    

    【讨论】:

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