mangati/paginator-bundle

Symfony4 paginator bundle

v1.1.0 2020-12-17 12:27 UTC

This package is auto-updated.

Last update: 2024-10-17 21:00:36 UTC


README

Symfony 4+ paginator bundle.

Usage

Controller:

// app controller

/**
 * @Route("/", name="my_index_route")
 */
public function index(Request $request, PaginatorFactory $paginatorFactory)
{
    $qb = $this
        ->getDoctrine()
        ->getManager()
        ->createQueryBuilder()
        ->select('e', 's')
        ->from(Entity::class, 'e');
    
    $query = $qb->getQuery();
    
    $paginator = $paginatorFactory
        ->withExtraParams(['q'])
        ->create(
            $request,
            $query,
            'my_index_route'
        );
    
    return $this->render('index.html.twig', [
        'paginator' => $paginator,
    ]);
}

View:

{# index.html.twig #}

<table>
    <thead>
        <tr>
            ...
        </tr>
    </thead>
    <tbody>
        {% for entity in paginator.result %}
            <tr>
                ...
            </tr>
        {% endfor %}
    </tbody>
</table>

{{ paginator.html|raw }}