11/12
2015
Wallogit.com
2017 © Pedro Peláez
Basic Paginator bundle for Symfony2
This is a simple bundle with 5 types of pagers (same as DataTables):, (*1)
No configurations are necessary., (*2)
<?php
// Acme/Bundle/Controller/DefaultController.php
// ...
public function indexAction()
{
$count = $repository->getAllUsersCount();
$paginator = $this->get('kr_paginator')->buildPaginator('simple_numbers', [
'totalItems' => $count, // required
'limit' => 5, // optional (default is 10)
'queryKey' => 'p', // optional (default is 'page')
'adjacentCount' => 3 // optional (default is 2)
]);
$limit = $paginator->getLimit();
$offset = $paginator->getOffset();
$results = $repository->getAllUsers($limit, $offset);
return $this->render('Bundle:Default:index.html.twig', [
'results' => $results,
'paginator' => $paginator->render()
]);
}
{{ paginator|raw }}
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*3)
$ composer require kr/kr-paginator-bundle "dev-master"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*4)
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:, (*5)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new KR\PaginatorBundle\KRPaginatorBundle(),
);
// ...
}
// ...
}