ecommit/paginator
Lightweight PHP paginator for arrays or ArrayIterator. Configure page, max_per_page, and data; optionally provide total count for large datasets. Iterate results, get last page, and use count() to know items on the current page.
Create a paginator.
To install paginator with Composer just run :
$ composer require ecommit/paginator
use Ecommit\Paginator\ArrayPaginator;
//Create a paginator
$paginator = new ArrayPaginator([
//Options
'page' => 1,
'max_per_page' => 100,
'data' => ['val1', 'val2', 'val3'],
//Or with an ArrayIterator
//'data' => new \ArrayIterator(['val1', 'val2', 'val3']),
]);
$totalPages = $paginator->getLastPage();
$countRows = \count($paginator);
foreach ($paginator as $result) {
//...
}
| Option | Type | Required | Default value | Description |
|---|---|---|---|---|
| page | Integer | No | 1 | Current page |
| max_per_page | Integer | No | 100 | Max elements per page |
| data | Array or ArrayIterator | Yes | If count option is null : All data (of all pages)If count option is not null : Only the data to display on the current page |
|
| count | Integer or null | No | Null | You can use this option when the data volume is too large. If the value is not null :It must equal the total number of resultsThe data option must contain only the data to display on the current page |
This librairy is under the MIT license. See the complete license in LICENSE file.
How can I help you explore Laravel packages today?