PHPackages                             vkr/pager-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. vkr/pager-bundle

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

vkr/pager-bundle
================

View-agnostic pager bundle for Symfony2/3

1.0.2(9y ago)032MITPHPPHP &gt;=5.6

Since Jul 17Pushed 9y ago1 watchersCompare

[ Source](https://github.com/wladislavk/PagerBundle)[ Packagist](https://packagist.org/packages/vkr/pager-bundle)[ Docs](https://github.com/wladislavk/PagerBundle)[ RSS](/packages/vkr-pager-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

About
=====

[](#about)

This is a simple pager bundle for Symfony. Unlike some other pagers, it is purely front-end agnostic and is written in SOA manner - you write your own service, then you get that service and Pager service from the controller, and then you get all the pagination data you need for later usage in the view layer.

This bundle depends upon VKRSettingsBundle, please read its docs before using it.

Installation
============

[](#installation)

There is almost nothing to do except enabling the bundle in Composer and AppKernel.php. However, if you want to use settings-based records per page, you will need to create a setting for every instance of pager you invoke. Read VKRSettingsBundle documentation for specifics on creating settings.

Usage
=====

[](#usage)

Parser
------

[](#parser)

There is a sole public method called `getPagerProps()`. In order to use it, you need to write a parser that implements `VKR\PagerBundle\Interfaces\PageableInterface`. This interface has a method called `getNumberOfRecords()` that should return the total number of records that can be shown using the pager. Here is an example of a parser class.

```
class MyParser implements VKR\PagerBundle\Interfaces\PageableInterface
{
    private $em;

    public function __construct(Doctrine\ORM\EntityManager $em)
    {
        $this->em = $em;
    }

    public function getNumberOfRecords(array $additionalArguments = [])
    {
        $allRecords = $this->em->getRepository('AppBundle:MyEntity')->findAll();
        if (!$allRecords) {
            return 0;
        }
        return sizeof($allRecords);
    }
}

```

Take a note that this query can be really slow on big chunks of data, so try to use aggregate functions and indexing.

Using additional arguments
--------------------------

[](#using-additional-arguments)

If your implementation of `getNumberOfRecords()` needs an argument, you have two options. You can either pass it as a class property, or use an optional $additionalArguments array, that is passed as fourth argument to `getPagerProps()` from the controller - this way is recommended for use cases when you do not need the query results anywhere else and you are registering your parser class as a service.

Parser:

```
public function getNumberOfRecords(array $additionalArguments = [])
{
    $query = "SELECT a FROM table1 a WHERE a.id IN ($additionalArguments['ids'])";
    ...
}

```

Controller:

```
public function myControllerAction()
{
    ...
    $additionalArguments = [
        'ids' => [1,2,3]
    ];
    $pagerProps = $pager->getPagerProps($parser, $request->getRequestUri(), $recordsPerPage, $additionalArguments);
    ...
}

```

Controller
----------

[](#controller)

Add this to your controller:

```
$parser = $this->get('my_parser_service');
$pager = $this->get('vkr_pager.pager');
$recordsPerPage = 20;
$pagerProps = $pager->getPagerProps($parser, $request->getRequestUri(), $recordsPerPage);

```

If you want to disable pagination and show all results on a single page, use

```
$recordsPerPage = -1;

```

One more way to use `getPagerProps()` is to define a setting for easier customization of `$recordsPerPage`. If you have such a setting, you can use it as a third argument:

```
$recordsPerPageSettingName = 'records_per_page';
$pagerProps = $pager->getPagerProps($parser, $request->getRequestUri(), $recordsPerPageSettingName);

```

The resulting `PagerProps` object is an in-memory entity with the following properties:

- `$currentPage` - the current page number, corresponds to the `page` query string parameter. Default is 1.
- `$uriWithoutPage` - the current page URI with all query string parameters except for `page`. It also has ? or &amp; appended to its end.
- `$recordsPerPage` - maximum number of records that can be displayed on a page.
- `$firstResult` - if you have a zero-indexed array of N records, this key tells the first index of a record that needs to be displayed on a current page. `$firstResult`and `$recordsPerPage` roughly correspond to two arguments of SQL LIMIT clause.
- `$numberOfPages` - total number of pages for your selection.

These properties are accessible via standard getters (`getCurrentPage()` etc).

Note that there are no actual records here, because this bundle does not make any DB queries. You need to write a class that would transform this data into a query.

Views
-----

[](#views)

You need to manually pass the resulting array to the view. This bundle does not help you to display things, so it can be used with any templating technique. There is a small example showing how it can be used in Twig at `Resources/views/pager_macro.html.twig`, it includes some Twitter Bootstrap classes.

If you are using Twig, you can also use a custom filter called `page()` that is included in the bundle. It appends page attribute to the query string.

```

```

API
===

[](#api)

*void Pager::\_\_construct(VKR\\SettingsBundle\\SettingsRetriever $settingsRetriever)*

*VKR\\PagerBundle\\Entity\\Perishable\\PagerProps Pager::getPagerProps(VKR\\PagerBundle\\Interfaces\\PageableInterface $parser, string $requestUri, int|string $recordsPerPageData, array $additionalArguments = \[\])*

If the third argument is a string, it is interpreted as a setting name, if it is integer, it is considered to be an actual number of records per page.

*int PageableInterface::getNumberOfRecords(array $additionalArguments = \[\])*

Gets the total number of records that can possibly be displayed in this view.

Also, there are getters and setters on *VKR\\PagerBundle\\Entity\\Perishable\\PagerProps* entity that are omitted for the sake of brevity.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~125 days

Total

3

Last Release

3339d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79f5fa971e7fda7a6180c1bdfca4f819a43b7681ec4e04c66b184a082fb5a20f?d=identicon)[wladislavk](/maintainers/wladislavk)

---

Top Contributors

[![wladislavk](https://avatars.githubusercontent.com/u/11371476?v=4)](https://github.com/wladislavk "wladislavk (3 commits)")

---

Tags

pagerpaginationSymfony2symfony3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vkr-pager-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/vkr-pager-bundle/health.svg)](https://phpackages.com/packages/vkr-pager-bundle)
```

###  Alternatives

[aws/aws-sdk-php-symfony

A Symfony bundle for v3 of the AWS SDK for PHP

36517.7M22](/packages/aws-aws-sdk-php-symfony)[aplus/pagination

Aplus Framework Pagination Library

2091.6M3](/packages/aplus-pagination)[kop/yii2-scroll-pager

Infinite AJAX scrolling for Yii2 ListView widget

180706.5k10](/packages/kop-yii2-scroll-pager)[ashleydawson/simple-pagination

Simple, lightweight and universal service that implements pagination on collections of things

18161.2k2](/packages/ashleydawson-simple-pagination)[ttskch/paginator-bundle

The most thin, simple and customizable paginator bundle for Symfony

1113.2k](/packages/ttskch-paginator-bundle)[abdielcs/expanded-collection-bundle

Symfony 2 and 3 bundle for rendering a collection of entities as an expanded selectable list

1210.1k](/packages/abdielcs-expanded-collection-bundle)

PHPackages © 2026

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