PHP code example of sivka / paginator

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

    

sivka / paginator example snippets


$paginator = new Paginator(
	$totalItems, 
	$itemsPerPage, 
	$currentPage, 
	'/foo/(:num)');

$paginator = new Paginator(
	$totalItems, 
	$itemsPerPage, 
	$currentPage, 
	'/foo/(:num)',
	false);

$paginator = new Paginator(
  $totalItems, 
  $itemsPerPage, 
  $currentPage, 
  function($pageNum){
    return '/page-' . $pageNum . '/';
  });


function getUrl($pageNum){
  return '/page-' . $pageNum . '/';
}

$paginator = new Paginator(
  $totalItems, 
  $itemsPerPage, 
  $currentPage, 
  'getUrl');


class myClass {
  function getUrl($pageNum){
    return '/page-' . $pageNum . '/';
  }
}

$obj = new myClass;

$paginator = new Paginator(
  $totalItems, 
  $itemsPerPage, 
  $currentPage, 
  [$obj, 'getUrl']);

    $paginator = new Paginator(200, 10);
    $paginator->size('sm');
    echo $paginator;

    $paginator = new Paginator(200, 10);
    $paginator->position('right');
    echo $paginator;

    $paginator = new Paginator(200, 10);
    $paginator->dimensions($position, $size);
    echo $paginator;

    $paginator = new Paginator(200, 10);
    $paginator->size('my-custom-size-class');
    $paginator->position('my-custom-position-class');
    echo $paginator;

    $paginator = new Paginator(200, 10);
    $paginator->dimensions('my-custom-position-class', 'my-custom-size-class');
    echo $paginator;

    
    
    inator;

    $totalItems = 1000;
    $itemsPerPage = 50;
    $currentPage = 8;
    $urlPattern = '/foo/page/(:num)';

    $paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);

    

    $paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);
    
    
html
    <ul class="pagination">
         if ($paginator->getPrevUrl()):