承接 metarush/pagination 相关项目开发

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

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

metarush/pagination

最新稳定版本:v1.0.0

Composer 安装命令:

composer require metarush/pagination

包简介

Standalone pagination module that is not tied to any frameworks

README 文档

README

Standalone pagination module that is not tied to any frameworks

Install

Install via composer as metarush/pagination

Sample usage

use MetaRush\Pagination\Builder;

// define minimum required vars

$currentPage = $_GET['page'] ? (int) $_GET['page'] : 1;
$path = '/demo.php?page=';
$totalItems = 50;
$itemsPerPage = 5;

Default config

$p = (new Builder)
    ->setTotalItems($totalItems)
    ->setItemsPerPage($itemsPerPage)
    ->setCurrentPage($currentPage)
    ->setPath($path)
    ->build();

Display:

echo $p->prevLink() . ' ' . $p->pageLinksUncut() . ' ' . $p->nextLink();

default config screenshot

Display as dropdown

Remove ->build(); from previous example then append the ff.

    ->setPageLink('<option>{{page}}</option>')
    ->setActiveLink('<option selected="selected">{{page}}</option>')
    ->build();

Note: You need the ff. sample Javascript code for the dropdown to work

<script>
    document.getElementById('myDropdown').addEventListener('change', (event) => {
        location.href = `<?=$path?>${event.target.value}`;
    });
</script>

Display:

echo $p->prevLink() . ' <select id="myDropdown">' . $p->pageLinksUncut() . '</select> ' . $p->nextLink();

display as dropdown screenshot

Auto-cut pagination

Remove ->setPageLink(), ->setActiveLink(), and ->build(); from previous example then append the ff.

    ->setPagesCutoff(5) // Estimated max number of page links to display (default: 7)
    ->build();

Display:

echo $p->prevLink() . ' ' . $p->pageLinksAutoCut() . ' ' . $p->nextLink();

auto-cut pagination screenshot

Custom look

Use custom HTML/CSS or frameworks like Bootstrap/Materialize/etc.

Remove ->build(); from previous example then append the ff.

    ->setPageLink('<li class="page-item"><a class="page-link" href="{{path}}{{page}}">{{page}}</a></li>')
    ->setActiveLink('<li class="page-item active"><span class="page-link">{{page}}</span></li>')
    ->setDisabledPrevLink('<li class="page-item disabled"><span class="page-link">Prev</span></li>')
    ->setDisabledNextLink('<li class="page-item disabled"><span class="page-link">Next</span></li>')
    ->setEllipsis('<li class="page-item"><span class="page-link">...</span></li>')
    ->setPrevLink('<li class="page-item"><a class="page-link" href="{{path}}{{page}}">Prev</a></li>')
    ->setNextLink('<li class="page-item"><a class="page-link" href="{{path}}{{page}}">Next</a></li>')
    ->build();

Display:

echo '<ul class="pagination">' . $p->prevLink() . ' ' . $p->pageLinksAutoCut() . ' ' . $p->nextLink().' </ul>';

custom look screenshot

Querying data from database

Code for querying of data from a database is intentionally not included in this module. This is best implemented in userland. Below are examples on how to do this:

First, determine $limit and $offset

$limit = $itemsPerPage;
$offset = ($itemsPerPage * $currentPage) - $itemsPerPage;

Raw SQL

$sql = "SELECT * FROM your_table LIMIT $limit OFFSET $offset";

Laravel query builder

$result = DB::table('your_table')
            ->offset($offset)
            ->limit($limit)
            ->get();

Doctrine DBAL query builder

$queryBuilder
    ->select('*')
    ->from('your_table')
    ->setFirstResult($offset)
    ->setMaxResults($limit);

Working demo

Check the demo in public/demo.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固