Skip to content

Instantly share code, notes, and snippets.

@gondo
Created July 22, 2014 18:57
Show Gist options
  • Save gondo/c24e196a8d3f159fb2ab to your computer and use it in GitHub Desktop.
Save gondo/c24e196a8d3f159fb2ab to your computer and use it in GitHub Desktop.

Revisions

  1. gondo created this gist Jul 22, 2014.
    35 changes: 35 additions & 0 deletions controller
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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,
    );
    }
    48 changes: 48 additions & 0 deletions view
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    {% 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 %}