PHP code example of sebastiansulinski / php-paginator
1. Go to this page and download the library: Download sebastiansulinski/php-paginator 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/ */
sebastiansulinski / php-paginator example snippets
// import all dependencies
use SSD\Paginator\Request;
use SSD\Paginator\Collection;
use SSD\Paginator\Pagination;
use SSD\Paginator\VueSelectPaginator;
// instantiate Pagination class
$pagination = new Pagination(
Request::capture(),
160,
10,
'page'
);
// get your records as array and pass through to the Collection
// in this example I just use array of numbers and get only a chunk
// of records based on offset and limit, but you'd probably use
// some active model to get only the records you're after
$records = range(1, 160);
$records = new Collection($records);
$chunk = $records->splice(
$pagination->offset(),
$pagination->limit()
);
// instantiate SelectPaginator with instance of Pagination and collection of records
$paginator = new VueSelectPaginator($pagination, $chunk);
// loop through records using Collection::map() and implode() methods
echo $paginator->records()->map(function($record) {
// ...
})->implode('');
// or using standard foreach loop
foreach($paginator->records() as $record) {
// ...
}
// display pagination
echo $paginator->render();