agusmoita/mottapg-bundle

Symfony的分页器包

安装次数: 77

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 1

开放问题: 3

类型:symfony-bundle

3.1.3 2019-08-07 13:36 UTC

This package is auto-updated.

Last update: 2024-09-08 00:25:40 UTC


README

安装

  • 通过Composer添加
    $ composer require agusmoita/mottapg-bundle

使用方法

  • 控制器

    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);
    }
  • 仓库

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

    {# 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 %}

许可证

MIT许可证