Skip to content

Instantly share code, notes, and snippets.

@gondo
Created July 22, 2014 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gondo/c24e196a8d3f159fb2ab to your computer and use it in GitHub Desktop.
Save gondo/c24e196a8d3f159fb2ab to your computer and use it in GitHub Desktop.
KnpPaginatorBundle multiple paginators example
public function listAction()
{
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('ExampleBundle:Entity');
$qb = $historyRepository->createQueryBuilder('EntityAlias');
$knpPaginator = $this->get('knp_paginator');
$paginationAAA = $knpPaginator->paginate(
$qb,
$this->get('request')->query->get('pageAAA', 1), // page number
10, // limit per page
array(
'pageParameterName' => 'pageAAA',
'sortFieldParameterName' => 'sortAAA',
'sortDirectionParameterName' => 'directionAAA',
)
);
$paginationBBB = $knpPaginator->paginate(
$qb,
$this->get('request')->query->get('pageBBB', 1), // page number
10, // limit per page
array(
'pageParameterName' => 'pageBBB',
'sortFieldParameterName' => 'sortBBB',
'sortDirectionParameterName' => 'directionBBB',
)
);
return array(
'paginationAAA' => $paginationAAA,
'paginationBBB' => $paginationBBB,
);
}
{% if paginationAAA.getTotalItemCount > 0 %}
<table>
<thead>
<tr>
<th>
{{ knp_pagination_sortable(paginationAAA, 'Field', 'EntityAlias.field', {'defaultDirection' : 'desc'}) }}
</th>
</tr>
</thead>
<tbody>
{% for rows in paginationAAA %}
<tr>
<td>
{{ row.field }}
</td>
{% endfor %}
</tbody>
</table>
{{ knp_pagination_render(paginationAAA) }}
{% else %}
No data.
{% endif %}
{% if paginationBBB.getTotalItemCount > 0 %}
<table>
<thead>
<tr>
<th>
{{ knp_pagination_sortable(paginationBBB, 'Field', 'EntityAlias.field', {'defaultDirection' : 'desc'}) }}
</th>
</tr>
</thead>
<tbody>
{% for rows in paginationBBB %}
<tr>
<td>
{{ row.field }}
</td>
{% endfor %}
</tbody>
</table>
{{ knp_pagination_render(paginationBBB) }}
{% else %}
No data.
{% endif %}
@alexol91
Copy link

Hi, it isn't working with my sliding.html.twig. The URL generated is "..?page=2" and I need change this parameter to "search_page" or "related_page".For pagers change page I put the URL, for example,"...?search_page=2". I not know as chage it.

{% if pageCount > 1 %}                        
    {% if first is defined and current != first %}
         <li><a href="{{ path(route, query|merge({(pageParameterName): first})) }}" class="image_link image_link_prev">
                <img src="/bundles/images/template/arrow_left_pag.png" alt="before" />
            </a>
        </li>
    {% endif %}

    {% if previous is defined %}
        <li><a href="{{ path(route, query|merge({(pageParameterName): previous})) }}" class="image_link image_link_prev">prev
            </a>
        </li>
    {% endif %}

    {% for page in pagesInRange %}
        {% if page != current %}
            <li>
                <a href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a>
            </li>
        {% else %}
            <li class="estoy">
               {{ page }}
            </li>
        {% endif %}

    {% endfor %}

    {% if next is defined %}
        <li>
            <a href="{{ path(route, query|merge({(pageParameterName): next})) }}" class="image_link image_link_next">next</a>
        </li>
    {% endif %}
    {% if last is defined and current != last %}
        <li><a href="{{ path(route, query|merge({(pageParameterName): last})) }}" class="image_link image_link_next">
                <img src="/bundles/images/template/arrow_right_pag.png" alt="next" />
            </a>
            </li>
    {% endif %}

{% endif %}

Help me please :(

@gondo
Copy link
Author

gondo commented Jul 23, 2014

why are you editing sliding.html.twig !? DONT touch that file at all! unless you know what are you doing, what clearly is not the case.
use {{ knp_pagination_render(paginationBBB) }}, see my example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment