https://github.com/compolomus/pagination
https://github.com/compolomus/pagination
pagination pagination-template
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/compolomus/pagination
- Owner: Compolomus
- License: mit
- Created: 2019-08-19T14:55:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-31T16:45:58.000Z (about 4 years ago)
- Last Synced: 2025-05-20T08:07:54.344Z (about 1 year ago)
- Topics: pagination, pagination-template
- Language: PHP
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Compolomus Pagination
[](https://packagist.org/packages/compolomus/Pagination)
[](https://scrutinizer-ci.com/g/Compolomus/Pagination/build-status/master)
[](https://scrutinizer-ci.com/g/Compolomus/Pagination/?branch=master)
[](https://scrutinizer-ci.com/g/Compolomus/Pagination/?branch=master)
[](https://codeclimate.com/github/Compolomus/Pagination)
[](https://packagist.org/packages/compolomus/Pagination)
## Установка:
composer require compolomus/pagination
## Применение:
```php
use Compolomus\Pagination\Pagination;
require __DIR__ . '/vendor/autoload.php';
$page = $_GET['page'] ?? 1;
$items = range(1, 200);
echo count($items);
#1
$nav = new Pagination((int) $page, 10, count($items), 7, true);
$navIntegers = new Pagination((int) $page, 10, count($items), 7);
for ($i = $nav->getOffset(); $i < $nav->getEnd(); $i++) {
echo '
' . $items[$i] . '';
}
#2
foreach (new LimitIterator(new ArrayIterator($items), $nav->getOffset(), $nav->getLimit()) as $item) {
echo '
' . $item . '';
}
#3
$count = 200; // select count(*) from table
$select = range(100, 1000, 100); // select * from table limit $nav->getLimit() offset $nav->getOffset()
/*
while($row = fetch($select)) {
// ...
}
*/
echo '
' . print_r($nav->get(), true) . '
';
/*
Array
(
[prev] => 9
[first] => 1
[second] => 2
[0] => 1
[leftDots] => ...
[1] => 3
[2] => 4
[3] => 5
[4] => 6
[5] => 7
[6] => 8
[7] => 9
[current] => 10
[8] => 11
[9] => 12
[10] => 13
[11] => 14
[12] => 15
[13] => 16
[14] => 17
[rightDots] => ...
[15] => 20
[last] => 20
[next] => 11
[preLast] => 19
)
*/
echo '
' . print_r($navIntegers->get(), true) . '
';
/*
Array
(
[0] => 1
[1] => ...
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
[10] => 11
[11] => 12
[12] => 13
[13] => 14
[14] => 15
[15] => 16
[16] => 17
[17] => ...
[18] => 20
)
*/
```