Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 9967e96542
Fetching contributors…

Cannot retrieve contributors at this time

110 lines (79 sloc) 3.276 kB

Intro to PaginatorBundle

This is a new version of Paginator Bundle which has been made reusable, extensible, highly customizable and simple to use Symfony2 paginating tool based on Zend Paginator.


  • Zend library paginator package, without any view helpers. In future this requirement may be dropped
  • Doctrine ODM or ORM active bundle.


  • Single adapter for Zend paginator, which can be used as ORM or ODM query paginator, using DIC
  • Possibility to add custom filtering, sorting functionality depending on request parameters.
  • Extensions based on events for ODM and ORM query customizations.
  • View helper for simplified pagination templates and other custom operations like sorting.
  • Supports multiple paginators during one request

Notice: using multiple paginators requires setting the alias for adapter in order to keep non conflicting parameters. Also it gets quite complicated with a twig template, since hash arrays cannot use variables as keys.

Installation and configuration:

Install Zend Framework 2

git submodule add git:// vendor/Zend

Get the bundle

Submodule the bundle

git submodule add git:// vendor/bundles/Knp/Bundle/PaginatorBundle

Yml configuration example

    templating: ~ # enables view helper and twig

Add the namespaces to your autoloader

// app/autoload.php
    'Knp'                       => __DIR__.'/../vendor/bundles',
    'Zend'                => __DIR__.'/../vendor/Zend/library',
    // ...

Add PaginatorBundle to your application kernel

// app/AppKernel.php
public function registerBundles()
    return array(
        // ...
        new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
        // ...

Usage examples:


$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT a FROM VendorBlogBundle:Article a";
$query = $em->createQuery($dql);

$adapter = $this->get('knp_paginator.adapter');

$paginator = new \Zend\Paginator\Paginator($adapter);
$paginator->setCurrentPageNumber($this->get('request')->query->get('page', 1));

// if second paginator is required on same view:

$adapterODM = $this->get('knp_paginator.adapter');
$adapterODM->setAlias('p2_'); // we do not want parameters to conflict
$paginator2 = new Paginator($adapterODM);


{# sorting of properties based on query components #}
    <th>{{ paginator|sortable('Id', '') }}</th>
    <th>{{ paginator|sortable('Title', 'a.title') }}</th>

{# table body #}
{% for article in paginator %}
<tr {% if loop.index is odd %}class="color"{% endif %}>
    <td>{{ }}</td>
    <td>{{ article.title }}</td>
{% endfor %}
{# display navigation #}
<div id="navigation">
    {{ paginator|paginate }}
Jump to Line
Something went wrong with that request. Please try again.