承接 swoopaholic/pagerfanta-bridge 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

swoopaholic/pagerfanta-bridge

Composer 安装命令:

composer require swoopaholic/pagerfanta-bridge

包简介

Swoopaholic Pagerfanta Bridge

README 文档

README

This small library is intended to remove the dependency on the Pagerfanta bundle and it's twig extensions. By using the view, you can create a template to render the pager.

Usage

Just download the library and use it in your symfony2 project controller:

/**
 * Lists all entities.
 *
 * @Route("/", name="my_entities")
 * @Method("GET")
 * @Template()
 */
public function indexAction(Request $request)
{
    $qb = $this->getDoctrine()->getManager()->createQueryBuilder('MyBundle:MyEntity');
    $adapter = new \Pagerfanta\Adapter\DoctrineORMAdapter($qb);
    
    $pager = new \Swoopaholic\Bridge\Pagerfanta\Pagerfanta($adapter);
    $pager->setCurrentPage($request->get('page', 1));
    $pager->setMaxPerPage(50);

    return array(
        'entities' => $pager->getData(),
        'pagerfanta' => $pager->createView(),
    );

Create a macro template for rendering the pager:

{% block page_first %}
    <li{% if pager.currentPage <= 1 %} class="disabled"{% endif %}><a href="{{ pager.first }}">&laquo;</a></li>
{% endblock %}

{% block page_last %}
    <li{% if pager.currentPage >= pager.pages|length %} class="disabled"{% endif %}><a href="{{ pager.last }}">&raquo;</a></li>
{% endblock %}

{% block page_prev %}
    <li{% if pager.currentPage <= 1 %} class="disabled"{% endif %}><a href="{{ pager.prev }}">&larr;</a></li>
{% endblock %}

{% block page_next %}
    <li{% if pager.currentPage >= pager.pages|length %} class="disabled"{% endif %}><a href="{{ pager.next }}">&rarr;</a></li>
{% endblock %}

{% block page_link %}
    <li{% if active %} class="active"{% endif %}><a href="{{ item.url }}">{{ item.content }}</a></li>
{% endblock %}

{% macro pager(pager) %}
    {% if pager.count > 1 %}
        <ul class="pagination">
            {{ block('page_first') }}
            {{ block('page_prev') }}
            {% for number,page in pager.pages %}
                {% set item = {'url': page, 'content': number} %}
                {% set active = number == pager.currentPage %}
                {{ block('page_link') }}
            {% endfor %}
            {{ block('page_next') }}
            {{ block('page_last') }}
        </ul>
    {% endif %}
{% endmacro %}

Using the macro 'pager' in a template with the view ('pagerfanta') is easy:

{% import 'MyLayoutTemplatesBundle:Navigation:pager.html.twig' as pager %}

...

{{ pager.pager(pagerfanta) }}

License

This bundle is released under the MIT license. See the complete license in the bundle:

LICENSE

统计信息

  • 总下载量: 1.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固