PHPackages                             knplabs/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. [Templating &amp; Views](/categories/templating)
4. /
5. knplabs/knp-paginator-bundle

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

knplabs/knp-paginator-bundle
============================

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

v6.10.0(5mo ago)1.8k42.8M—7.2%335[15 issues](https://github.com/KnpLabs/KnpPaginatorBundle/issues)[1 PRs](https://github.com/KnpLabs/KnpPaginatorBundle/pulls)20MITPHPPHP ^8.1CI passing

Since Jan 18Pushed 5mo ago47 watchersCompare

[ Source](https://github.com/KnpLabs/KnpPaginatorBundle)[ Packagist](https://packagist.org/packages/knplabs/knp-paginator-bundle)[ Docs](https://github.com/KnpLabs/KnpPaginatorBundle)[ RSS](/packages/knplabs-knp-paginator-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (57)Used By (20)

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

[](#intro-to-knppaginatorbundle)

Friendly Symfony paginator to paginate everything

[![Build Status](https://github.com/KnpLabs/KnpPaginatorBundle/workflows/Build/badge.svg)](https://github.com/KnpLabs/KnpPaginatorBundle/actions)

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

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

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

[](#latest-updates)

For details regarding changes please read about the [releases](https://github.com/KnpLabs/KnpPaginatorBundle/releases).

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

[](#requirements)

- Knp Pager component `>=4.4`.
- KnpPaginatorBundle's master is compatible with Symfony `>=6.4` versions.
- Twig `>=3.0` version is required if you use the Twig templating engine.
- If you want to use the provided templates, you need the Translation component too.

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/docs/custom_pagination_subscribers.md "Custom pagination subscribers")
- [Customizing view](https://github.com/KnpLabs/KnpPaginatorBundle/tree/master/docs/templates.md "Customizing Pagination templates") templates and arguments

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

[](#installation-and-configuration)

### Pretty simple with [Composer](https://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)

If you don't use flex (you should), you need to manually enable bundle:

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

### Configuration example

[](#configuration-example)

You can configure default query parameter names and templates, and a few other options:

#### YAML:

[](#yaml)

```
knp_paginator:
    convert_exception: false            # throw a 404 exception when an invalid page is requested
    page_range: 5                       # number of links shown 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)
    remove_first_page_param: false      # remove the page query parameter from the first page link
    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
        page_out_of_range: ignore       # ignore, fix, or throwException when the page is out of range
        default_limit: 10               # default number of items per page
    template:
        pagination: '@KnpPaginator/Pagination/sliding.html.twig'     # sliding pagination controls template
        rel_links: '@KnpPaginator/Pagination/rel_links.html.twig'    #  tags template
        sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template
        filtration: '@KnpPaginator/Pagination/filtration.html.twig'  # filters template
```

#### PHP:

[](#php)

```
// config/packages/paginator.php
