Download the PHP package beberlei/porpaginas without Composer
On this page you can find all versions of the php package beberlei/porpaginas. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download beberlei/porpaginas
More information about beberlei/porpaginas
Files in beberlei/porpaginas
Package porpaginas
Short Description Library that generically solves several pagination issues with DAO/repository abstractions.
License MIT
Informations about the package porpaginas
Porpaginas
This library solves a bunch of issues that comes up with APIs of Repository classes alot:
- You need different methods for paginatable and non-paginatable finder methods.
- You need to expose the underlying data-source and return query objects from your repository.
- Serialization of paginators should be easily possible for REST APIs
Both Pagerfanta and KnpLabs Pager don't solve this issue and their APIs are really problematic in this regard. You need to return the query objects or adapters for paginators from your repositories to get it working and then use an API on the controller side to turn them into a paginated result set.
Porpaginas solves this by introducing a sane abstraction for paginated results. For rendering purposes you can integrate with either Pagerfanta or KnpLabs Pager, this library is not about reimplementating the view part of pagination.
Central part of this library is the interface Result
:
This API offers you two ways to iterate over the paginatable result,
either the full result or a paginated window of the result using take()
.
One drawback is that the query is always lazily executed inside
the Result
and not directly in the repository.
The Page
interface returned from Result#take()
looks like this:
You can use the IteratorPage
in your own implementations, if the underlying
data-source is itself an iterator.
Supported Backends
- Array
- Doctrine ORM
Example
Take the following example using Doctrine ORM:
Now in the template for porpaginasListAction
using the porpaginas
Twig
extension for example:
Pager Library Support
- For Pagerfanta use the
Porpaginas\Pagerfanta\PorpaginasAdapter
and pass it a result as first argument.
Embedded Pager
You can use the Porpaginas\Pager
class to help you get a slice of previous and next pages to display:
Passed to a twig template: