Skip to content

augustomoita/MottaPgBundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MottaPgBundle


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