PHP code example of dotzero / ypaginator

1. Go to this page and download the library: Download dotzero/ypaginator 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/ */

    

dotzero / ypaginator example snippets


$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);

[
    "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
];


bash
$ git clone https://github.com/dotzero/ypaginator-php