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 %}
@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