This package is for creating simple pagination links based on the current page number, and the total number of records.
The pagination output will look something like this:
Install via composer
Using the paginator is easy. All you need is a current page number, the total number of records, and a PSR-7 URI object such as
Zend's Diactoros. Several frameworks, such as Slim, already include a
PSR-7 Uri object as part of the
1 2 3 4 5 6 7 8 9 10 11 12 13
And the result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
With the generic decorator, it is up to you to create the CSS for display. See the page on the generic decorator for some sample CSS.
Changing the paging (rows per page)
You can easily modify the paging from the default of 10 to any number. This should match any paging you are using in your DB queries or ORM.
1 2 3 4 5 6 7 8
Changing the query parameter
The default query parameter is 'page'. You can change that by using the 4th
parameter on the
1 2 3
The resulting href will look like this
Getting metadata about the pagination
You can get an array of metadata about the pagingation by calling
you have called the
paginate() method. The
getMeta() method needs to know the
current page and the total pages, so it must come after
With this metadata, you can do things like "Showing 1 to 10 of 432"
1 2 3 4
$meta might look like this, depending on your arguments.
1 2 3 4 5 6 7 8 9
Getting and setting the decorator
At anytime after constructing the paginator, you can get the decorator by calling
$decorator = $paginator->getDecorator(). This allows you to modify decorator config options prior
to outputting the html.
If you need to set a new decorator after construction, you can call the