PHP code example of pnixx / pagination

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

    

pnixx / pagination example snippets




use PNixx\Pagination\Pagination;
$pagination = new Pagination();

// Set the total number of items
$pagination->setTotalItems(45);

// Render html
echo $pagination->render(); 



// Total number of items. This one MUST be set.
$pagination->setTotalItems($total_items);

// setTotalItems() alias
$pagination->setItems($total_items);

// Sets the number of items (lines) in a single page.
$pagination->setItemsPerPage($per_page);

// setItemsPerPage() alias
$pagination->setLimit($per_page);

// Sets the page number manually.
$pagination->setPage($page);

/*
 * Sets the URI pattern for creating links for pages.
 * Default pattern is "page={page}"  (URLs like /posts/show?page=5)
 * Can be set for example to "p={page}" or anything else for $_GET parameter
 * Can be set also to "page/{page}" for friendly URLs. In this case Pagination
 * will build URLs like: /posts/show/page/5
 */
$pagination->setPattern($pattern);

/*
 * Sets the current URI. Default is $_SERVER["REQUEST_URI"]
 * Handy for unit tests.
 */
$pagination->setUri($uri);

// Sets the proximity. See getProximity() above for more explanations.
$pagination->setProximity($proximity);

// Prev and Next labels
$pagination->setLabelPrev($label_prev);
$pagination->setLabelNext($label_next);

// Show arrows always or only not on the first or last page. Default: true (always)
$pagination->setShowArrowIfNeed($show_arrow_if_need);



$pagination = new Pagination([
    'items' => 100, // or 'total'
    'per_page' => 10,
    'proximity' => 3,
    'uri' => 'http://example.com/show/page:6',
    'pattern' => 'page:{page}',
    'page' => 6,
])