Pretty simple with Composer, run:
composer req gpslab/pagination-bundle
Default configuration
gpslab_pagination:
# Page range used in pagination control
max_navigate: 5
# Name of URL parameter for page number
parameter_name: 'page'
# Sliding pagination controls template
template: 'GpsLabPaginationBundle::pagination.html.twig'
use GpsLab\Bundle\PaginationBundle\Service\Configuration;
class ArticleController extends Controller
{
private const ARTICLES_PER_PAGE = 30;
public function index(ArticleRepository $rep, Configuration $pagination): Response
{
$pagination->setTotalPages(ceil($rep->getTotalPublished() / self::ARTICLES_PER_PAGE));
// get articles chunk
$offset = ($pagination->getCurrentPage() - 1) * self::ARTICLES_PER_PAGE;
$articles = $rep->getPublished(self::ARTICLES_PER_PAGE, $offset);
return $this->render('AcmeDemoBundle:Article:index.html.twig', [
'articles' => $articles,
'pagination' => $pagination
]);
}
}
Display pagination in template:
<nav class="pagination">
{{- pagination_render(pagination) -}}
</nav>
- Base usage
- From QueryBuilder
- From HTTP request
- From HTTP request and QueryBuilder
- Request parameter name
- Navigation pages range
- Custom view
This bundle is under the MIT license. See the complete license in the file: LICENSE