KnpPaginatorBundle paginates and sorts data in Symfony apps using the Knp Pager component. It works with Doctrine, arrays, and other targets without dedicated adapter setup per type.
Overview
KnpPaginatorBundle is a Symfony bundle built on the Knp Pager component. It provides pagination and sorting aimed at being SEO friendly, using an event-dispatcher flow where subscribers paginate supported target types and build a pagination view for rendering.
Pagination can wrap arrays, Doctrine ORM and DBAL queries, MongoDB ODM queries, Propel criteria, Solarium selects, collections, and more. Custom subscribers can add new target types, such as paginating filesystem directory listings. Multiple paginators in one app can use aliases to keep query parameters separate.
Twig templates ship for pagination links, sortable headers, filtration, and rel link tags across Bootstrap, Foundation, Bulma, Semantic UI, Tailwind, UIkit, and other styles. Configuration covers default template keys, query parameter names, and optional translation domains for pager labels.
The bundle targets Symfony 6.4 and later with Knp Pager component 4.4+, Twig 3 when using bundled templates, and Symfony Translation when using those templates. The paginator service can be injected via constructor autowiring; lazy instantiation is available when Symfony's proxy-manager bridge is installed.
Key features
- Event-based pagination pipeline
- Doctrine ORM and ODM support
- Custom pagination subscribers
- Sortable and filterable views
- Multiple CSS framework templates
- SEO rel link template
- Configurable query parameter names
- Injectable paginator service
Use cases
- Paginating Symfony controller result sets
- Sortable admin tables with Twig
- Doctrine query pagination
- Custom data source pagination via subscribers