Download the PHP package vkr/pager-bundle without Composer
On this page you can find all versions of the php package vkr/pager-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vkr/pager-bundle
More information about vkr/pager-bundle
Files in vkr/pager-bundle
Package pager-bundle
Short Description View-agnostic pager bundle for Symfony2/3
License MIT
Homepage https://github.com/wladislavk/PagerBundle
Informations about the package pager-bundle
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
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
Parser
There is a sole public method called . In order to use it, you need to write a parser that implements . This interface has a method called that should return the total number of records that can be shown using the pager. Here is an example of a parser class.
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
If your implementation of 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 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:
Controller:
Controller
Add this to your controller:
If you want to disable pagination and show all results on a single page, use
One more way to use is to define a setting for easier customization of . If you have such a setting, you can use it as a third argument:
The resulting object is an in-memory entity with the following properties:
-
- the current page number, corresponds to the query string parameter. Default is 1.
-
- the current page URI with all query string parameters except for . It also has ? or & appended to its end.
-
- maximum number of records that can be displayed on a page.
-
- 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. and roughly correspond to two arguments of SQL LIMIT clause.
-
- total number of pages for your selection.
These properties are accessible via standard getters ( 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
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 , it includes some Twitter Bootstrap classes.
If you are using Twig, you can also use a custom filter called that is included in the bundle. It appends page attribute to the query string.
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.