pagination.php
<?php
/**
* Pagination sample
*/
/**
* @uses Pagination class
*/
use Applications\Site\Models\Pages;
use Progik\Utils\Paginator;
// GET name that will use to pass the current page
$urlPageAttribute = 'page';
// Current page is defined with the GET variable page
$currentPage = isset($_GET[$urlPageAttribute]) ? $_GET[$urlPageAttribute] : 1;
// Define the number of record per page to display (is the limit in SQL)
$nbPerPage = 25;
// Define the current starting offset for SQL offset
$offSet = ($currentPage-1)*$nbPerPage;
// Define search conditions to pass to the model
$search = '';
// Set the default total to zero
$total = 0;
// The paginator maximum number of page to display
$maxNbPage = 5;
<table>
<thead>
<tr>
<th><?=__('#');?></th>
<th><?=__('Name');?></th>
</tr>
</thead>
<tbody>
<?php
// Query model
if($pages = Pages::find($search, $nbPerPage, $offSet)) {
/* @var $page Pages */
foreach($pages as $page) {
?>
<tr>
<td><?=$page->getId();?></td>
<td><?=$page->getName();?></td>
</tr>
<?php
}
// Get the total of possible result
// This is equivalent of doing a SELECT COUNT with the same search conditions
$total = $pages->count(true);
} else {
echo '<tr><td colspan="2"><b>'.__('No page found!').'</b></td></tr>';
}
?>
</tbody>
</table>
<?php
/**
* Display pagination
*
*
* There is 2 way you could use the paginator.
* The following way let you change variable before displaying it.
*
* $paginator = new Paginator($currentPage, $total, $nbPerPage, $maxNbPage, $urlPageAttribute);
* $paginate->currentClass = 'active';
* $paginate->showFirst = false;
* $paginate->showLast = false;
* $paginate->showNext = false;
* $paginate->showPrev = false;
* $paginate->tplBefore = '<ul class="filterPagi">';
* $paginator->display();
*
* The other version is in static mode
* Paginator::render($currentPage, $total, $nbPerPage, $maxNbPage, $urlPageAttribute);
*/
Paginator::render($currentPage, $total, $nbPerPage, $maxNbPage, $urlPageAttribute);