看起来我还有另一个分页问题。当我遍历下面的分页数组时,我得到了每一页的整个数组。
$array = [...];
$ret = new LengthAwarePaginator($array, count($array), 10);
// dd($ret);
LengthAwarePaginator {#302 ▼
#total: 97
#lastPage: 10
#items: Collection {#201 ▼
#items: array:97 [▶]
}
#perPage: 10
#currentPage: 1
#path: "/"
#query: []
#fragment: null
#pageName: "page"
}这不是从一个雄辩的模型构建一圈的情况,例如:Blah::paginate()
发布于 2015-04-09 08:35:49
分页器不会自动对给定的数组进行切片。在将其传递给分页器之前,您必须自己对其进行切片。
为了让您的工作更轻松,可以使用collect辅助对象创建一个laravel集合的实例,这使得对其进行切片非常容易:
$items = collect([...]);
$page = Input::get('page', 1);
$perPage = 10;
$paginator = new LengthAwarePaginator(
$items->forPage($page, $perPage), $items->count(), $perPage, $page
);发布于 2015-04-09 08:05:14
LengthAwarePaginator不会自动分块。
一种快速的解决方法是做一些类似的事情:
foreach($col->slice($col->perPage() * ($col->currentPage() - 1), $col->perPage()) as $item)
{
// do blah
}https://stackoverflow.com/questions/29527064
复制相似问题