1. 云栖社区>
  2. PHP教程>
  3. 正文

Eloquent and Pagination Inside Zend Expressive

作者:用户 来源:互联网 时间:2017-12-01 17:25:19

Eloquent and Pagination Inside Zend Expressive - 摘要: 本文讲的是Eloquent and Pagination Inside Zend Expressive, Recently working with eloquent (Laravel’s orm), zend expressive and zend view, I wanted to integrate pagination. It wa

Recently working with eloquent (Laravel’s orm), zend expressive and zend view, I wanted to integrate pagination.

It was simple as registering a Paginatormiddleware.

use Illuminate/Pagination/Paginator;use Psr/Http/Message/ResponseInterface;use Psr/Http/Message/ServerRequestInterface;IlluminatePaginator::currentPageResolver(function ($pageName) use ($request) { $params = $request->getQueryParams(); return empty($params[$pageName]) ? 1 : $params[$pageName];});IlluminatePaginator::currentPathResolver(function () use ($request) { return $request->getUri()->getPath();});

and you can call paginate on the Model.

Eg : Consider you have a Postmodel.

$posts = Post::paginate(20);

and in view you can iterate through the $postsand render the pagination. The $postsis an object of LengthAwarePaginator.

You can also modify the presenter accordingly. Default comes with BootstrapThreePresenter

<?phpforeach ($this->posts as $post) {?> <?= $post->title . "<br />" ?><?php}?><?= $this->posts->render() ?>

Note : Please be aware of the issues/10909.

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索,以便于您获取更多的相关知识。