Open-source project
KnpLabs/KnpPaginatorBundle avatar
KnpLabs/KnpPaginatorBundle

KnpPaginatorBundle for Symfony Pagination and Sorting

SEO friendly Symfony paginator to sort and paginate

1,825 stars330 forksPHPMIT

At a glance

What is it?
KnpPaginatorBundle adds configurable pagination, sorting, filtering, and SEO link rendering to Symfony applications through the Knp Pager component. It suits developers who want query-string controls and customizable Twig output without a fixed adapter setup.
Who is it for?
Adopt KnpPaginatorBundle when a Symfony application needs Twig-based pagination controls, sortable query parameters, filtering hooks, and rel links without selecting a pagination adapter. Use v3.0 or v4.X for ODM MongoDB or ORM 2.0 query pagination, as the README directs.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 42 days ago.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

KnpPaginatorBundle's Symfony Pagination Boundary

KnpPaginatorBundle is intended for Symfony developers who need one interface for pagination, sorting, filtering, and the links search engines can interpret. It is not a standalone database query engine. Its foundation is the separate Knp Pager component, and the bundle builds the pagination view around that component. The README describes this as a separation of concerns: the paginator generates the pagination view, while that view handles representation.

That boundary matters when choosing a design. The bundle can produce page navigation, sort links, filtering controls, and `<link rel="...">` tags, but it does not claim to decide what database query should return. The application remains responsible for supplying the result set or adapting its query. This makes the bundle suitable for many Symfony backends, although the README does not enumerate every integration supported by the current Knp Pager component.

The bundle also does not require a specific adapter to be initialized. That can simplify integration compared with a setup tied to one query mechanism. It does not mean adapters or application services are irrelevant. If the application uses Doctrine ORM or another persistence layer, the developer still has to connect that layer to the paging component correctly. The README does not provide a complete controller and query example, so installation alone should not be treated as a working end-to-end query integration.

Page, Sort, and Filter Request Flow

KnpPaginatorBundle expresses pagination state through configurable request parameter names. The documented defaults are `page` for the page, `sort` for the sort field, and `direction` for sort direction. Filtering has separate defaults named `filterField` and `filterValue`. These names become part of the URL contract for a paginated listing, so changing them after routes, links, analytics, bookmarks, or indexing have been established can affect more than the Twig template.

The `default_limit` setting controls how many items a page contains by default, with the documented value set to `10`. The `page_range` value controls how many page links appear in the pagination menu. With a range of `5`, the README explains that the fifth page of a ten-page result can expose links around that position. This is view-range behavior, not the maximum number of records returned.

Out-of-range requests are handled through `page_out_of_range`, whose documented choices are `ignore`, `fix`, and `throwException`. This setting forces an application decision about malformed URLs. Ignoring an out-of-range request can leave a caller with a page label that does not correspond to useful content, while fixing the page moves it into the valid range. Throwing an exception suits applications that want invalid pagination URLs rejected rather than normalized. The related `convert_exception` setting is documented as controlling conversion to a 404 exception for an invalid page request.

Sorting and filtering are extension points rather than a universal query builder. The bundle states that custom filtering and sorting can depend on request parameters, and it links to documentation for custom pagination subscribers. That subscriber model lets developers attach application-specific event handling without putting every rule inside the shipped templates. The README does not specify which fields are safe to sort, how authorization is enforced, or how arbitrary `sort` values become ORM expressions. Those checks must remain application concerns.

Composer Installation and Bundle Registration

The documented installation path starts with Composer. This adds the bundle to a Symfony project using the package name published for this repository.

bash
composer require knplabs/knp-paginator-bundle

After that command, projects that do not use Flex must register the bundle themselves. The README's kernel example uses the bundle class below. Symfony Flex projects can normally use the package's recipe-based setup, although the repository does not include the recipe details in the README.

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

The requirements are specific enough to affect upgrade planning. Knp PaginatorBundle's `master` branch is documented as compatible with Symfony `>=6.4`. Twig `>=3.0` is required when Twig is used, and Symfony's Translation component is required for the provided templates. The separate Knp Pager component must be `>=4.4`.

The README does not document a minimal Twig variable name or a controller invocation for a first query. It therefore does not provide enough information here for a complete first-use example. A developer following the README can install and register the bundle, configure it, and then consult the linked Pager logic and pagination documentation for the application-specific query and rendering step.

YAML Defaults for Pagination Output

The documented YAML configuration centralizes request names, invalid-page behavior, and Twig templates. The following excerpt uses the keys shown in the README and keeps the pagination and rel-link template assignments visible.

yaml
knp_paginator:
    convert_exception: false
    page_range: 5
    remove_first_page_param: false
    default_options:
        page_name: page
        sort_field_name: sort
        sort_direction_name: direction
        distinct: true
        filter_field_name: filterField
        filter_value_name: filterValue
        page_out_of_range: ignore
        default_limit: 10
    template:
        pagination: '@KnpPaginator/Pagination/sliding.html.twig'
        rel_links: '@KnpPaginator/Pagination/rel_links.html.twig'

The default pagination view is `@KnpPaginator/Pagination/sliding.html.twig`. The repository also lists Bootstrap, Bulma, Foundation, Materialize, Semantic UI, Tailwind CSS, and UIkit templates. These provide different markup conventions, but the README does not claim that any one of them automatically satisfies a site's accessibility requirements. A developer choosing among them must inspect the rendered controls in the application's CSS and Twig context.

For SEO-oriented output, `rel_links` points to `@KnpPaginator/Pagination/rel_links.html.twig`. The bundle separates those links from visible pagination because crawlers and browsers consume different link types. The default `remove_first_page_param: false` keeps the documented default page parameter behavior. Setting that option to `true` removes `page` from the first-page link, which can produce cleaner URLs, but the README does not document crawler handling or a separate canonical tag in this configuration.

Twig Customization and Multiple Paginator Constraints

Presentation is deliberately extensible. The configuration assigns separate templates for visible pagination, rel links, sortable links, and filtration. A project can therefore change the representation without changing the request parameter defaults, while custom pagination subscribers can handle application-specific behavior.

This separation does not remove the need to understand query-string behavior. A sortable link changes the sort field or direction parameter, and a filter control populates the configured field and value parameters. If two paginated lists appear on one page and both use the defaults, they can collide because both read and write the same names. The README gives a direct warning: multiple paginators require an `alias` to avoid conflicting parameters. That makes `alias` a practical requirement rather than a cosmetic option for pages containing several independent listings.

The shipped templates also create compatibility obligations. Twig `>=3.0` is required, and Translation is needed for the provided templates. Projects with existing Twig extensions or custom variables should review template customization documentation rather than assuming every template can be copied unchanged. The README names customization areas but does not promise compatibility with arbitrary third-party pagination markup.

For filtering, the explicit field and value parameter names do not authorize fields or define query syntax. The repository offers custom subscribers as the extension point, which is appropriate for cases where a listing depends on an entity-specific filter model. The README does not state whether filters are cached, whether values are escaped in every custom implementation, or how sorting maps to database columns. Those are concrete checks for a concrete application.

KnpPaginatorBundle Versus Manual Symfony List Rendering

The closest documented alternative is implementing page calculations, sort and filter parameters, and navigation markup directly in a Symfony controller and Twig template. That approach gives an application full control over every request parameter and rendered element, but the project itself must maintain valid ranges, page links, sort transitions, filter state, and SEO rel links.

KnpPaginatorBundle takes responsibility for the shared pagination-view layer while leaving query adaptation and domain-specific event handling with the application. It also supplies several framework and CSS-oriented Twig templates, an explicit rel-links template, configurable parameter names, and support for pagination subscribers. Those are concrete differences from maintaining a one-off list view.

The trade-off is dependency alignment. The README says to keep `knp-components` in sync with KnpPaginatorBundle. Applications therefore carry an integration cost beyond installing one Symfony package. The bundle is a poor fit if the application cannot accommodate the documented Symfony, Twig, Translation, and Knp Pager constraints, or if its pagination state must be completely independent of the Knp Pager model.

Version choice also excludes some legacy cases. The README directs users of older KnpPaginatorBundle versions to the `v3.0` or `v4.X` tags when they need to paginate ODM MongoDB or ORM 2.0 queries. Current `master` is presented for newer Symfony compatibility, but the README does not provide a support matrix for every Doctrine combination.

Release History and Upgrade Obligations

The repository is not archived, and its last push was on 2026-09-11. The latest listed release is `v6.11.0`, also dated 2026-09-11, following `v6.10.0` from 2025-11-29 and `v6.9.1` from 2025-07-25. These facts indicate recent repository activity, but the release list alone does not establish compatibility with a particular Symfony application.

The primary upgrade instruction is concrete: keep `knp-components` in sync with KnpPaginatorBundle. Because the bundle is based on the Knp Pager component, version drift can complicate Composer resolution or alter assumptions shared across the package boundary. The documented Knp Pager floor is `>=4.4`, while master targets Symfony `>=6.4`. Twig and Translation apply only when the relevant rendering features are used.

The project uses the MIT license. That identifies the license recorded for the repository, but this review does not provide legal advice about dependency licenses or obligations in a particular distribution. The release notes are the documented source for detailed changes, so an upgrade decision should compare the selected bundle release with those notes and the versions resolved for `knp-components`.

Editorial conclusion

Adopt KnpPaginatorBundle when a Symfony application needs Twig-based pagination controls, sortable query parameters, filtering hooks, and rel links without selecting a pagination adapter. Use v3.0 or v4.X for ODM MongoDB or ORM 2.0 query pagination, as the README directs. Before adoption, verify that your Symfony, Twig, Translation, and Knp Pager versions satisfy the documented constraints, then confirm that knp-components can be kept in sync and that the default templates match your page design.

Frequently asked questions

How do I install KnpPaginatorBundle in a Symfony application?

Run `composer require knplabs/knp-paginator-bundle`. If the project does not use Flex, register `Knp\Bundle\PaginatorBundle\KnpPaginatorBundle` in the kernel.

Which Symfony and Twig versions does KnpPaginatorBundle require?

The documented `master` branch supports Symfony `>=6.4`. Twig `>=3.0` is required when using Twig, and the Translation component is required for the provided templates.

How do I keep multiple KnpPaginatorBundle instances from sharing query parameters?

Set a distinct `alias` for each paginator. The README states that multiple paginators require an alias to prevent conflicting request parameters.

What should KnpPaginatorBundle do when a requested page is out of range?

Configure `page_out_of_range` as `ignore`, `fix`, or `throwException`. The separate `convert_exception` option controls whether an invalid page request is converted into a 404 exception.

Official sources

  1. KnpLabs/KnpPaginatorBundle on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/knplabs-knppaginatorbundle.svg)](https://hysenlabs.com/projects/knplabs-knppaginatorbundle)

Was this useful?