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 |
|
|
count | Integer or null | No | Null | You can use this option when the data volume is too large. If the value is not null :
|
This librairy is under the MIT license. See the complete license in LICENSE file.