compolomus / pagination
Pagination
v1.2
2022-03-31 16:38 UTC
Requires
- php: ^8.0
Requires (Dev)
- laminas/laminas-coding-standard: ^1.0
- phpunit/phpunit: ^9.5
Suggests
- ext-xdebug: ^3.0
This package is auto-updated.
Last update: 2024-11-29 06:47:06 UTC
README
Установка:
composer require compolomus/pagination
Применение:
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 '<div>' . $items[$i] . '</div>'; } #2 foreach (new LimitIterator(new ArrayIterator($items), $nav->getOffset(), $nav->getLimit()) as $item) { echo '<div>' . $item . '</div>'; } #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 '<pre>' . print_r($nav->get(), true) . '</pre>'; /* 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 '<pre>' . print_r($navIntegers->get(), true) . '</pre>'; /* 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 ) */