指定分页页面 - Laravel 4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17386641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Specify a page for pagination - Laravel 4
提问by wyred
I'm trying to "remember" the page the user was on as he browses through records so that when he returns to the list, he is returned to the page where he left off.
我试图“记住”用户浏览记录时所在的页面,以便当他返回列表时,他会返回到他离开的页面。
How do I change the "current page" value for paginator?
如何更改分页器的“当前页面”值?
I've tried Input::set('page', $x); but there's no such function. $_GET['page'] = $x; doesn't work too.
我试过 Input::set('page', $x); 但是没有这个功能。$_GET['page'] = $x; 也不起作用。
This the code:
这是代码:
$list = Publication::orderBy($this->data['sort_by'], $this->data['order_by']);
foreach ($this->data['filter_data'] AS $field => $value) {
$list->where($field, 'LIKE', "%$value%");
}
$this->data['list'] = $list->paginate(15);
采纳答案by Jason Lewis
You can adjust the page of the pagination environment through the DB connection.
可以通过DB连接调整分页环境的页面。
DB::getPaginator()->setCurrentPage(2);
Not entirely sure but you might be able to go through your model with something like this.
不完全确定,但您可能可以使用这样的东西来浏览您的模型。
Publication::getConnection()->setCurrentPage(2);
If the above isn't working (as it seems from your comment), then do it with an instance of Publication
.
如果上述方法不起作用(从您的评论中可以看出),请使用Publication
.
$publication = new Publication;
$publication->getConnection()->setCurrentPage(2);
$list = $publication->orderBy(...);
回答by Andrew
I looked at the API --- turns out this is much easier now in 2014.
我查看了 API --- 事实证明这在 2014 年变得容易多了。
All you have to do is set
您所要做的就是设置
Paginator::setCurrentPage(2);
any time before you call ->paginate()
, I believe, and it should override the page set (or not set) by ?page=
.
->paginate()
我相信,在您调用 之前的任何时间,它都应该覆盖由 设置(或未设置)的页面?page=
。
回答by Ryun
Try
尝试
$pager->setCurrentPage(2);