dotzero / ypaginator
This package is abandoned and no longer maintained.
No replacement package was suggested.
A lightweight PHP paginator without a database dependency, for generating pagination controls in the style of Yandex
0.7
2016-04-13 18:42 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is auto-updated.
Last update: 2022-06-04 08:40:12 UTC
README
A lightweight PHP paginator without a database dependency, for generating pagination controls in the style of Yandex.
Features
- The
first
andlast
page links are shown - The
current
andneighbours
page links are shown - Rest of links are replaced by ellipses
How it looks like:
<< previous | next >>
|1| ... |5||6||7| ... |100|
Usage
$total = 100; // Total items $perpage = 10; // Items per page $current = 5; // Current page $neighbours = 2; // Neighbours links beside current page $y = new \dotzero\YPaginator($total, $perpage, $current); $paginator = $y ->setNeighbours($neighbours) ->setUrlMask('#num#') ->setUrlTemplate('/foo/page/#num#') ->getPaginator(); print_r($paginator);
Output looks like:
[ "prev" => ["name" => 4,"url" => "/foo/page/4","current" => false], // Previous "pages" => [ ["name" => 1,"url" => "/foo/page/1","current" => false], // First ["name" => "...","url" => "/foo/page/2","current" => false], ["name" => 3,"url" => "/foo/page/3","current" => false], // Neighbour ["name" => 4,"url" => "/foo/page/4","current" => false], // Neighbour ["name" => 5,"url" => "/foo/page/5","current" => true], // Current ["name" => 6,"url" => "/foo/page/6","current" => false], // Neighbour ["name" => 7,"url" => "/foo/page/7","current" => false], // Neighbour ["name" => "...","url" => "/foo/page/8","current" => false], ["name" => 10,"url" => "/foo/page/10","current" => false] // Last ], "next" => ["name" => 6,"url" => "/foo/page/6","current" => false] // Next ];
Install
Via composer:
$ composer require dotzero/ypaginator
Without composer
Clone the project using:
$ git clone https://github.com/dotzero/ypaginator-php
and include the source files with:
require_once("ypaginator-php/src/YPaginator.php");
Test
First install the dependencies, and after you can run:
$ vendor/bin/phpunit
License
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php