hefekranz / pagination
a simple lib to create a pagination from a symfony request
Installs: 118
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/hefekranz/pagination
Requires
- php: ^7.0
- symfony/http-foundation: ^3.2
Requires (Dev)
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2025-10-12 09:52:16 UTC
README
This is a very simple one. You take a request. You take the count of whatever items you want to display.
You put them together, you get a pagination object.
Installation
composer require hefekranz/pagination
Usage
Quick Example for GET /collection?page=2&limit=10 on a collection of 100 items
public function getMeSomeCollectionAction(Request $request) { $data = $objectRepo->findAll(); $pagination = (new Pagination($objectRepo->count(), $request))->build(); return new JsonResponse([ "pagination" => $pagination->toArray(), "data" => $data->toArray() ]); }
Would produce
{
"pagination": {
"total": 100,
"pages": {
"first": 1,
"previous": 1,
"current": 1,
"next": 2,
"last": 5
},
"links": {
"first": "/collection?page=1&limit=20",
"previous": "/collection?page=1&limit=20",
"current": "/collection?page=1&limit=20",
"next": "/collection?page=2&limit=20",
"last": "/collection?page=5&limit=20"
}
},
"data": [
{},
{},
{}
]
}
The class expects a Symfony\HttpFoundation\Request object. If you dont have one, build it.
From the global request, or your custom implementation.
$request = Request::create("/collection","GET",["page" => 2,"limit" => 10]); /** or Request::createFromGlobals() */ $pagination = (new Pagination($objectRepo->count(), $request))->build();