agusmoita/mottapg-bundle

A paginator bundle for Symfony

3.1.3 2019-08-07 13:36 UTC

This package is auto-updated.

Last update: 2021-04-07 17:20:14 UTC


README

Installation

  • Add via composer
    $ composer require agusmoita/mottapg-bundle

Usage

  • Controller

    use MottaPgBundle\Util\Paginator\Paginator;
    
    /**
     * @Route("/", name="person_index", methods={"GET|POST"})
     */
    public function indexAction(Paginator $pg, PersonRepository $repo)
    {
        return $pg
                ->setView('person/index.html.twig')
                ->paginate($repo);
    }
  • Repository

    // PersonRepository.php
    
    public function buildQuery($query, $pg)
    {
        // return SELECT a FROM AppBundle:Person a
        return $query;
    }
  • View

    {# person/index.html.twig #}
    
    {% extends '@MottaPg/Paginator/table.html.twig' %}
    
    {% block title %}
        <h1>List of People</h1>
    {% endblock %}
    
    {% block paginator_table_header %}
        <th>First Name</th>
        <th>Last Name</th>
        <th>Birthday</th>
    {% endblock %}
    
    {% block paginator_table_data %}
        <td>{{ entity.firstName }}</td>
        <td>{{ entity.lastName }}</td>
        <td>{{ entity.birthday|date('m-d-Y') }}</td>
    {% endblock %}

License

MIT License