PHPackages                             metaship-ru/knp-paginator-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. metaship-ru/knp-paginator-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

metaship-ru/knp-paginator-bundle
================================

Paginator bundle for Symfony to automate pagination and simplify sorting and other features

0.1.3(5y ago)0251MITPHPPHP ^7.1CI failing

Since Apr 3Pushed 5y ago1 watchersCompare

[ Source](https://github.com/metaship-ru/knp-paginator-bundle)[ Packagist](https://packagist.org/packages/metaship-ru/knp-paginator-bundle)[ Docs](http://github.com/KnpLabs/KnpPaginatorBundle)[ RSS](/packages/metaship-ru-knp-paginator-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

Intro to KnpPaginatorBundle
===========================

[](#intro-to-knppaginatorbundle)

**SEO** friendly Symfony paginator to paginate everything

[![Build Status](https://camo.githubusercontent.com/9d92628e8e0dd30686deb22cc982a852c704fcf4063d8f947195d0065414085f/68747470733a2f2f7472617669732d63692e6f72672f4b6e704c6162732f4b6e70506167696e61746f7242756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/KnpLabs/KnpPaginatorBundle)

Generally this bundle is based on [Knp Pager component](https://github.com/KnpLabs/knp-components/blob/master/doc/pager/intro.md "Knp Pager component introduction"). This component introduces a different way for pagination handling. You can read more about the internal logic on the given documentation link.

[![knpbundles.com](https://camo.githubusercontent.com/59277339f6981bcb987f9c8d176045f2d9a36cd37bd430ce86b93fb42a1cd1ff/687474703a2f2f6b6e7062756e646c65732e636f6d2f4b6e704c6162732f4b6e70506167696e61746f7242756e646c652f62616467652d73686f7274)](http://knpbundles.com/KnpLabs/KnpPaginatorBundle)

**Note:** Keep **knp-components** in sync with this bundle. If you want to use older version of KnpPaginatorBundle - use **v1.0** tag in the repository which is suitable to paginate **ODM MongoDB** and **ORM 2.0** queries

Latest updates
--------------

[](#latest-updates)

For notes about latest changes please read [`CHANGELOG`](https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/CHANGELOG.md), for required changes in your code please read [`UPGRADE`](https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/upgrade.md)chapter of documentation.

Requirements:
-------------

[](#requirements)

- Knp Pager component `>=1.1`.
- KnpPaginatorBundle's master compatible with Symfony `>=2.7` versions.
- Twig `>=1.5` version is required if you use twig templating engine.

Features:
---------

[](#features)

- Does not require initializing specific adapters.
- Can be customized in any way needed, etc.: pagination view, event subscribers.
- Possibility to add custom filtering, sorting functionality depending on request parameters.
- Separation of concerns, paginator is responsible for generating the pagination view only, pagination view - for representation purposes.

**Note:** using multiple paginators requires setting the **alias** in order to keep non conflicting parameters.

More detailed documentation:
----------------------------

[](#more-detailed-documentation)

- Creating [custom pagination subscribers](https://github.com/KnpLabs/KnpPaginatorBundle/tree/master/Resources/doc/custom_pagination_subscribers.md "Custom pagination subscribers")
- [Extending pagination](#) class (todo, may require some refactoring)
- [Customizing view](https://github.com/KnpLabs/KnpPaginatorBundle/tree/master/Resources/doc/templates.md "Customizing Pagination templates") templates and arguments

Installation and configuration:
-------------------------------

[](#installation-and-configuration)

### Pretty simple with [Composer](http://packagist.org), run

[](#pretty-simple-with-composer-run)

```
composer require knplabs/knp-paginator-bundle
```

### Add PaginatorBundle to your application kernel

[](#add-paginatorbundle-to-your-application-kernel)

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

### Configuration example

[](#configuration-example)

You can configure default query parameter names and templates

```
knp_paginator:
    page_range: 5                       # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6)
    default_options:
        page_name: page                 # page query parameter name
        sort_field_name: sort           # sort field query parameter name
        sort_direction_name: direction  # sort direction query parameter name
        distinct: true                  # ensure distinct results, useful when ORM queries are using GROUP BY statements
        filter_field_name: filterField  # filter field query parameter name
        filter_value_name: filterValue  # filter value query parameter name
    template:
        pagination: '@KnpPaginator/Pagination/sliding.html.twig'     # sliding pagination controls template
        sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
        filtration: '@KnpPaginator/Pagination/filtration.html.twig'  # filters template
```

#### Additional pagination templates

[](#additional-pagination-templates)

That could be used out of the box in `knp_paginator.template.pagination` key:

- `@KnpPaginator/Pagination/sliding.html.twig` (by default)
- `@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig`
- `@KnpPaginator/Pagination/twitter_bootstrap_v3_pagination.html.twig`
- `@KnpPaginator/Pagination/twitter_bootstrap_pagination.html.twig`
- `@KnpPaginator/Pagination/foundation_v5_pagination.html.twig`
- `@KnpPaginator/Pagination/bulma_pagination.html.twig`
- `@KnpPaginator/Pagination/semantic_ui_pagination.html.twig`
- `@KnpPaginator/Pagination/materialize_pagination.html.twig`

#### Additional sortable templates

[](#additional-sortable-templates)

That could be used out of the box in `knp_paginator.template.sortable` key:

- `@KnpPaginator/Pagination/sortable_link.html.twig` (by default)
- `@KnpPaginator/Pagination/twitter_bootstrap_v3_sortable_link.html.twig`
- `@KnpPaginator/Pagination/font_awesome_sortable_link.html.twig`

Usage examples:
---------------

[](#usage-examples)

### Controller

[](#controller)

Currently paginator can paginate:

- `array`
- `Doctrine\ORM\Query`
- `Doctrine\ORM\QueryBuilder`
- `Doctrine\ODM\MongoDB\Query\Query`
- `Doctrine\ODM\MongoDB\Query\Builder`
- `Doctrine\ODM\PHPCR\Query\Query`
- `Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder`
- `Doctrine\Common\Collection\ArrayCollection` - any Doctrine relation collection including
- `ModelCriteria` - Propel ORM query
- array with `Solarium_Client` and `Solarium_Query_Select` as elements

```
// Acme\MainBundle\Controller\ArticleController.php

public function listAction(Request $request)
{
    $em    = $this->get('doctrine.orm.entity_manager');
    $dql   = "SELECT a FROM AcmeMainBundle:Article a";
    $query = $em->createQuery($dql);

    $paginator  = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
        $query, /* query NOT result */
        $request->query->getInt('page', 1), /*page number*/
        10 /*limit per page*/
    );

    // parameters to template
    return $this->render('AcmeMainBundle:Article:list.html.twig', array('pagination' => $pagination));
}
```

### View

[](#view)

```
{# total items count #}

    {{ pagination.getTotalItemCount }}

        {# sorting of properties based on query components #}
        {{ knp_pagination_sortable(pagination, 'Id', 'a.id') }}
        {{ knp_pagination_sortable(pagination, 'Title', 'a.title') }}
        {{ knp_pagination_sortable(pagination, 'Release', ['a.date', 'a.time']) }}

    {# table body #}
    {% for article in pagination %}

            {{ article.id }}
            {{ article.title }}
            {{ article.date | date('Y-m-d') }}, {{ article.time | date('H:i:s') }}

    {% endfor %}

{# display navigation #}

    {{ knp_pagination_render(pagination) }}

```

### Translation in view

[](#translation-in-view)

For translating the following text:

- `%foo% name` with translation key `table_header_name`. The translation is in the domain `messages`.
- `{0} No author|{1} Author|[2,Inf] Authors` with translation key `table_header_author`. The translation is in the domain `messages`.

translationCount and translationParameters can be combined.

```

       {# sorting of properties based on query components #}
       {{ knp_pagination_sortable(pagination, 'Id'|trans({foo:'bar'},'messages'), 'a.id' )|raw }}
       {{ knp_pagination_sortable(pagination, 'Title', 'a.title')|raw }}
       {{ knp_pagination_sortable(pagination, 'Author'|trans({}, 'messages'), 'a.author' )|raw }}

```

### Dependency Injection

[](#dependency-injection)

You can automatically inject a paginator service into another service by using the `knp_paginator.injectable` DIC tag. The tag takes one optional argument `paginator`, which is the ID of the paginator service that should be injected. It defaults to `knp_paginator`.

The class that receives the KnpPaginator service must implement `Knp\Bundle\PaginatorBundle\Definition\PaginatorAwareInterface`. If you're too lazy you can also just extend the `Knp\Bundle\PaginatorBundle\Definition\PaginatorAware` base class.

#### Lazy service

[](#lazy-service)

The `knp_paginator` service will be created lazily if the package `ocramius/proxy-manager` is installed.

For more information about lazy services, consult the [Symfony documentation on dependency injection](https://symfony.com/doc/current/service_container/lazy_services.html).

###### XML configuration example

[](#xml-configuration-example)

```

        MyBundle\Repository\PaginatorAwareRepository

```

Troubleshooting
---------------

[](#troubleshooting)

- Make sure the translator is activated in your symfony config:

```
framework:
    translator: { fallbacks: ['%locale%'] }
```

- If your locale is not available, create your own translation file in `app/Resources/translations/KnpPaginatorBundle.en.yml` (substitute en for your own language code if needed) . Then add these lines:

```
label_next: Next
label_previous: Previous
```

Maintainers
-----------

[](#maintainers)

- [@NiR-](https://github.com/NiR-)
- [@nicolasmure](https://github.com/nicolasmure)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor4

4 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~109 days

Total

2

Last Release

2120d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3992825?v=4)[Vovchikus](/maintainers/Vovchikus)[@Vovchikus](https://github.com/Vovchikus)

---

Top Contributors

[![l3pp4rd](https://avatars.githubusercontent.com/u/132389?v=4)](https://github.com/l3pp4rd "l3pp4rd (90 commits)")[![nicolasmure](https://avatars.githubusercontent.com/u/4362252?v=4)](https://github.com/nicolasmure "nicolasmure (31 commits)")[![polc](https://avatars.githubusercontent.com/u/3513348?v=4)](https://github.com/polc "polc (27 commits)")[![stloyd](https://avatars.githubusercontent.com/u/67402?v=4)](https://github.com/stloyd "stloyd (23 commits)")[![ornicar](https://avatars.githubusercontent.com/u/140370?v=4)](https://github.com/ornicar "ornicar (21 commits)")[![pilot](https://avatars.githubusercontent.com/u/28564?v=4)](https://github.com/pilot "pilot (19 commits)")[![garak](https://avatars.githubusercontent.com/u/179866?v=4)](https://github.com/garak "garak (11 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (10 commits)")[![Herzult](https://avatars.githubusercontent.com/u/177588?v=4)](https://github.com/Herzult "Herzult (9 commits)")[![inoryy](https://avatars.githubusercontent.com/u/195271?v=4)](https://github.com/inoryy "inoryy (7 commits)")[![docteurklein](https://avatars.githubusercontent.com/u/109846?v=4)](https://github.com/docteurklein "docteurklein (7 commits)")[![Kocal](https://avatars.githubusercontent.com/u/2103975?v=4)](https://github.com/Kocal "Kocal (7 commits)")[![roukmoute](https://avatars.githubusercontent.com/u/2140469?v=4)](https://github.com/roukmoute "roukmoute (6 commits)")[![marcelorodrigo](https://avatars.githubusercontent.com/u/443962?v=4)](https://github.com/marcelorodrigo "marcelorodrigo (5 commits)")[![mbontemps](https://avatars.githubusercontent.com/u/231249?v=4)](https://github.com/mbontemps "mbontemps (5 commits)")[![crackcomm](https://avatars.githubusercontent.com/u/206368?v=4)](https://github.com/crackcomm "crackcomm (5 commits)")[![ostrolucky](https://avatars.githubusercontent.com/u/496233?v=4)](https://github.com/ostrolucky "ostrolucky (5 commits)")[![TorbenLundsgaard](https://avatars.githubusercontent.com/u/15211444?v=4)](https://github.com/TorbenLundsgaard "TorbenLundsgaard (4 commits)")[![andreybolonin](https://avatars.githubusercontent.com/u/2576509?v=4)](https://github.com/andreybolonin "andreybolonin (4 commits)")[![jawadmjn](https://avatars.githubusercontent.com/u/12748654?v=4)](https://github.com/jawadmjn "jawadmjn (4 commits)")

---

Tags

symfonybundleknpknplabspagerpaginatorpagination

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/metaship-ru-knp-paginator-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/metaship-ru-knp-paginator-bundle/health.svg)](https://phpackages.com/packages/metaship-ru-knp-paginator-bundle)
```

###  Alternatives

[knplabs/knp-paginator-bundle

Paginator bundle for Symfony to automate pagination and simplify sorting and other features

1.8k42.8M315](/packages/knplabs-knp-paginator-bundle)[knplabs/knp-components

Knplabs component library

77343.6M46](/packages/knplabs-knp-components)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[ttskch/paginator-bundle

The most thin, simple and customizable paginator bundle for Symfony

1113.2k](/packages/ttskch-paginator-bundle)[slope-it/breadcrumb-bundle

A bundle for generating dynamic breadcrumbs in Symfony applications

1865.5k](/packages/slope-it-breadcrumb-bundle)[data-dog/pager-bundle

Paginator bundle for symfony2 and doctrine orm, allows customization with filters and sorters

11103.5k7](/packages/data-dog-pager-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
