https://github.com/e-commit/paginator
https://github.com/e-commit/paginator
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/e-commit/paginator
- Owner: e-commit
- License: mit
- Created: 2021-05-16T17:32:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-01T12:58:27.000Z (about 2 years ago)
- Last Synced: 2024-04-25T04:45:02.975Z (almost 2 years ago)
- Language: PHP
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Paginator
Create a paginator.

## Installation ##
To install paginator with Composer just run :
```bash
$ composer require ecommit/paginator
```
## Usage ##
```php
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) {
//...
}
```
### Available options
| 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 results
- The `data` option must contain only the data to display on the current page
### Available methods
See [API documentation](src/PaginatorInterface.php)
## License ##
This librairy is under the MIT license. See the complete license in *LICENSE* file.