指定分页页面 - Laravel 4 [英] Specify a page for pagination - Laravel 4

查看:14
本文介绍了指定分页页面 - Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图记住"用户浏览记录时所在的页面,以便当他返回列表时,他会返回到他离开的页面.

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?

我试过 Input::set('page', $x);但是没有这个功能.$_GET['page'] = $x;也不起作用.

I've tried Input::set('page', $x); but there's no such function. $_GET['page'] = $x; doesn't work too.

这是代码:

$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);

推荐答案

可以通过DB连接调整分页环境的页面.

You can adjust the page of the pagination environment through the DB connection.

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);

如果上述方法不起作用(从您的评论中可以看出),请使用 Publication 的实例进行处理.

If the above isn't working (as it seems from your comment), then do it with an instance of Publication.

$publication = new Publication;

$publication->getConnection()->setCurrentPage(2);

$list = $publication->orderBy(...);

这篇关于指定分页页面 - Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆