Kunwar Siddharth Singh Kunwar Siddharth Singh - 3 months ago 17x
PHP Question

How to implement rel=prev and rel=next to Symfony2.3 pagination?

I am using Symfony2.3 for my project and for pagination I am using KNP paginator Bundle.
I want to know that How I can implement rel=prev and rel=next in our page ?

My Controller :


namespace XXX\ABCBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Session\Session;
use Doctrine\ORM\EntityManager;

* author Siddharth Singh (siddharth.find@gmail.com)
class ArcController extends Controller {

* @Route("/arch", name="_arch")
* @Template()
public function indexAction() {
$em = $this->getDoctrine()->getEntityManager();
$AArtEntity = $em->getRepository('XXXABCBundle:Arc')->findAll(array('updated'=>'DESC'));
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$AArtEntity, $this->get('request')->query->get('page', 1)/* page number */, 10/* limit per page */


return array('article' => $pagination);


Twig File :-

{% extends 'XXXABCBundle::layout.html.twig' %}
{% block body %}
{% for artic in article %}
<div class="txt">
{% endfor %}
<div class="arcive_Paging">
<ul class="ul_paging">
<span class="acitve">{{ knp_pagination_render(article) }}</span>
{% endblock %}

Thanks !


You can do it by overriding default pagination template. Check Templates part of the official documentation:


for example:

Tell KnpPaginatorBundle to load your template for rendering pagination, add these lines of code to config.yml:

        pagination: YourBundle::pagination.html.twig

And copy default pagination template code to your template in src/YourBundle/Resources/views/pagination.html.twig. You can get the code here: