1. Go to this page and download the library: Download germania-kg/pagination library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
germania-kg / pagination example snippets
<?hpp
use Germania\Pagination\Pagination;
$items_count = 100; // count( $things ) or integer;
$pagination = new Pagination( $items_count );
$pagination->getPagesCount(); // 4, with 25 items each
$pagination->getFirst(); // 0
$pagination->getLast(); // 3
use Germania\Pagination\PaginationFactory;
// Optinally set default page size
$factory = new PaginationFactory;
$factory = new PaginationFactory( 25 );
// Most simple: just integers
$items_count = 65;
$choose_page = 2;
// Create Pagination instance:
$pagination = $factory( $items_count, $choose_page );
// Both elements are optional.
$pagination = $factory( $items_count, [
'number' => 2, // default: 0
'size' => 20
]);
// User Input
$pagination = $factory( $items_count, $_GET['page'] ?? [] );
use Germania\Pagination\PaginationIterator;
// Have your pagination at hand...
$pagination = ...
$pagination->setCurrent(2);
// Setup something really big
$collection = new MyHugeIterator( $thousand_items );
$paginated_collection = new PaginationIterator( $collection, $pagination );
echo count( $paginated_collection ); // 25
foreach( $paginated_collection as $item):
// loop: 25 items on page 2
endforeach;
// this time, we do not pick a page number!
$thousand_items = ...
$pagination = new Pagination( count($thousand_items) );
$pagination->isActive(); // null
$collection = new MyHugeIterator( $thousand_items );
$paginated_collection = new PaginationIterator( $collection, $pagination );
$iterator = $paginated_collection->getIterator();
get_class( $iterator ); // MyHugeIterator instance