PHP code example of forrest79 / pagination

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

    

forrest79 / pagination example snippets


$pages = Forrest79\Pagination\PagesFactory::all(100);
$pages = Forrest79\Pagination\PagesFactory::neighbour(100, 1, 5);
$pages = Forrest79\Pagination\PagesFactory::logarithmic(100, 10, 10);

class Paginator extends Nette\Utils\Paginator
{

	public function pages(): array
	{
		if ($this->getPageCount() === null) {
			throw new InvalidArgumentException('We need page count set to generate pages list');
		}
		return Forrest79\Pagination\PagesFactory::logarithmic($this->getPageCount(), $this->getPage(), 10);
	}

}

<li n:foreach="$paginator->pages() as $page" n:class="$page === $paginator->getPage() ? active, $page === null ? disabled">
	{if $page === null}
		..
	{else}
		<a n:href="this, page => $page">{$page}</a>
	{/if}
</li>