README.md

Pagerfanta

Pagination for PHP 5.3

Usage

<?phpusePagerfanta\Pagerfanta;usePagerfanta\Adapter\ArrayAdapter;$adapter=newArrayAdapter($array);$pagerfanta=newPagerfanta($adapter);$pagerfanta->setMaxPerPage($maxPerPage); // 10 by default$maxPerPage=$pagerfanta->getMaxPerPage();$pagerfanta->setCurrentPage($currentPage); // 1 by default$currentPage=$pagerfanta->getCurrentPage();$nbResults=$pagerfanta->getNbResults();$currentPageResults=$pagerfanta->getCurrentPageResults();$pagerfanta->getNbPages();$pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page$pagerfanta->hasPreviousPage();$pagerfanta->getPreviousPage();$pagerfanta->hasNextPage();$pagerfanta->getNextPage();

The ->setMaxPerPage() and ->setCurrentPage() methods implement a fluent interface:

All of them extends from Pagerfanta\Exception\NotValidCurrentPageException.

Adapters

The adapter's concept is very simple. An adapter just returns the number of results and an slice for a offset and length. This way you can adapt a pagerfanta to paginate any kind results simply creating an adapter.

An adapter must implement the Pagerfanta\Adapter\AdapterInterface interface, which has these two methods:

DoctrineCollectionAdapter

To paginate a Doctrine\Common\Collection\Collections interface you can use the DoctrineCollectionAdapter. It proxies to the count() and slice() methods on the Collections interface for pagination. This makes sense if you are using Doctrine ORMs Extra Lazy association features: