A lightweight PHP paginator.
Add in your composer.json
with following require entry:
{
"require": {
"wake/pager": "*"
}
}
or using composer:
$ composer require wake/pager:*
then run composer install
or composer update
.
Use Pager without any ORM.
Use Pager\Pager;
$pager = new Pager ();
$pager->total (1000) // 1000 data items
->page (13) // Set current page to no.13
->paging ();
// First page: 1
echo $pager->pages->top;
// Last page (total pages): 67
echo $pager->pages->end;
// First page of page group: 8
echo $page->pages->first;
// Last page of page group: 17
echo $page->pages->last;
// Next page: 14
echo $page->pages->next;
// Next 10 page: 24
echo $page->pages->next10;
// Pages
foreach ($pager->pages as $page)
echo $page . "<br />";
// Page url
foreach ($pager->pages as $page)
echo $page->url . "<br />";
Set amount of items per page, default to 15
.
// Display 12 items on each page.
$pager->show (12);
Set total amount of items.
// Set total amount of 100.
$pager->total (100);
Set amount of page list per page, default to 10
.
// Display 5 pages of page group on each page - `1 2 3 4 5`
$pager->size (5);
Set current page, default to 1
.
// Set current to page 3
$pager->page (3);
List pages of page group dynamically or fixed, default is dynamic
.
// List dynamically: `1 2 3 4 5` -> `2 3 4 5 6` -> `3 4 5 6 7`
$pager->dynamic ();
// List fixed: `1 2 3 4 5` -> `6 7 8 9 10`
$pager->fixed ();
Set url pattern or handler function, default is pattern (:num)
.
// /?page=3
$pager->url ('/?page=(:num)');
// /?p=3
$pager->url (function ($pageItem) {
return '/?p=' . $pageItem->num;
});
Calculate and build page items, must be called after all options are set.
$pager->paging ();
Container of page items.
Use Pager\Pager;
$pager = new Pager ();
$pager->total (1000) // 1000 data items
->page (13) // current page is no.13
->paging ();
$pages = $pager->pages;
First page of all pages, generally is 1.
Last page of all pages.
First page of page group.
Last page of page group.
Total amount of pages.
Current page.
Next page.
Previous page.
Next N
page.
// Next page
$pages->next;
$pages->next1;
// Next 5 page
$pages->next5;
Previous N
page.
// Previous page
$pages->prev;
$pages->prev1;
// Previous 5 page
$pages->prev5;
Page item.
Use Pager\Pager;
$pager = new Pager ();
$pager->total (1000) // 1000 data items
->page (13) // current page is no.13
->paging ();
$item = $pager->pages->first;
Number of the page, $item could be use as string directly.
echo $item;
echo $item->num;
Url of the page.
echo $item->url ();
Please feel free to open an issue and let me know if there is any thoughts or questions 😃
Released under the MIT license