Paginator library

v0.2.2 2015-04-27 10:44 UTC

This package is auto-updated.

Last update: 2021-01-06 01:07:16 UTC


Build Status Scrutinizer Code Quality SensioLabsInsight


$ php composer.phar require 'anh/paginator:0.2.*'


Create paginator and call it's paginate() method with data, page number and number of elements per page. It will find appropriate adapter and return Page instance, filled with paginated data, it can be used in foreach directly. Also you can pass manually created adapter instead of data.


use Anh\Paginator\Paginator;

$query = /* ORM Query or QueryBuilder for fetching users */;

$paginator = new Paginator();
$users = $paginator->paginate($query, 1, 10);

foreach ($users as $user) {
    // do something with user

If you need to pass options to adapter, pass it to paginate() as fourth parameter. Note each adapter has own options.


use Anh\Paginator\Paginator;
use Anh\Paginator\Adapter\ArrayAdapter;

$data = array(/* elements */);

$paginator = new Paginator();
$elements = $paginator->paginate($data, 3, 20, array('preserveKeys' => true));

foreach ($elements as $key => $element) {
    // do something with element

You can create custom adapters and add them to AdapterResolver. All adapters must implement AdapterInterface interface.


use Anh\Paginator\Paginator;
use Anh\Paginator\AdapterResolver;

$adapterResolver = new AdapterResolver();

$paginator = new Paginator($adapterResolver);
$elements = $paginator->paginate($data, $pageNumber, $elementsPerPage);

foreach ($elements as $element) {
    // do something with element



use Anh\Paginator\Paginator;
use Anh\Paginator\View\AdaptiveView;

$paginator = new Paginator();
$posts = $paginator->paginate(/* ... */);

$view = new AdaptiveView();
$view->setTemplates(array(/* templates */));
$view->setOptions(array(/* options */));

echo $view->render($posts, '/some/url/page-%page%', array(/* options */));

For complete list of templates and options see sources. Also you can use resource/pagination.css for paginator styling. It is based on pagination from foundation zurb.

Available adapters

  • EmptyDataAdapter
  • ArrayAdapter
  • DoctrineOrmAdapter


Library uses semantic versioning.