adamb/pagination
Composer 安装命令:
composer require adamb/pagination
包简介
Creates bootstrap themed pagination buttons
README 文档
README
Pagination
Create a HTML pagination element using PHP. Compatible with Bootstrap and easily customisable classes.
Installation
Installation is available via Composer/Packagist, you can add the following line to your composer.json file:
"adamb/pagination": "^1.0"
or
composer require adamb/pagination
License
This software is distributed under the MIT license. Please read LICENSE for information on the software availability and distribution.
Features
- Creates a pagination HTML element
- Compatible with Bootstrap 3/4
- Change the class names assigned to the elements
- Easily change maximum number of links show
- If only 1 page exists no pager will be displayed
Usage
1. Creating the pagination HTML
PHP Code
<?php require "src\Pagination.php"; use Pager\Pagination; $numberOfRecords = 342; // This can also be generated from a database query $pageURL = '/results.php'; $currentPage = $_GET['page']; $resultsPerPage = 50; // This is the default value so can be removed $pagination = new Pagination(); echo($pagination->paging($numberOfRecords, $pageURL, $currentPage, $resultsPerPage));
HTML Output
<ul class="pagination"> <li class="active"><a href="/results.php?page=1" title="Page 1">1</a></li> <li><a href="/results.php?page=2" title="Page 2">2</a></li> <li><a href="/results.php?page=3" title="Page 3">3</a></li> <li><a href="/results.php?page=4" title="Page 4">4</a></li> <li><a href="/results.php?page=5" title="Page 5">5</a></li> <li><a href="/results.php?page=6" title="Page 6">6</a></li> <li><a href="/results.php?page=7" title="Page 7">7</a></li> <li><a href="/results.php?page=2" title="Page >">></a></li> <li><a href="/results.php?page=7" title="Page »">»</a></li> </ul>
2. Changing the class names added to the HTML elements
PHP Code
<?php require "src\Pagination.php"; use Pager\Pagination; $numberOfRecords = 342; // This can also be generated from a database query $pageURL = '/results.php'; $currentPage = 3; //$_GET['page']; $pagination = new Pagination(); $pagination->setPaginationClass('my_custom_pager') ->setActiveClass('this_is_active'); echo($pagination->paging($numberOfRecords, $pageURL, $currentPage));
HTML Output
<ul class="my_custom_pager"> <li><a href="/results.php" title="Page «">«</a></li> <li><a href="/results.php?page=2" title="Page <"><</a></li> <li><a href="/results.php?page=1" title="Page 1">1</a></li> <li><a href="/results.php?page=2" title="Page 2">2</a></li> <li class="this_is_active"><a href="/results.php?page=3" title="Page 3">3</a></li> <li><a href="/results.php?page=4" title="Page 4">4</a></li> <li><a href="/results.php?page=5" title="Page 5">5</a></li> <li><a href="/results.php?page=6" title="Page 6">6</a></li> <li><a href="/results.php?page=7" title="Page 7">7</a></li> <li><a href="/results.php?page=4" title="Page >">></a></li> <li><a href="/results.php?page=7" title="Page »">»</a></li> </ul>
3. Additional features
There are a range of options available to customise for your project, here you can customise things such as the number of items being displayed each page witch will either increase or reduce the number of links. You can also change the maximum number of buttons show, turn off the display of the arrow buttons and also add additions items to the URL query string.
PHP Code
<?php require "src\Pagination.php"; use Pager\Pagination; $numberOfRecords = 2042; $pageURL = '/results.php'; $currentPage = 3; //$_GET['page']; $resultsPerPage = 100; $maximumLinksToDisplay = 9; $displayArrows = false; $additionalQuery = array( 'search' => 'Hello', // urlencode($_GET['search']), 'important_info' => 42, // urlencode($_GET['important_info']), ); $pagination = new Pagination(); echo($pagination->paging($numberOfRecords, $pageURL, $currentPage, $resultsPerPage, $maximumLinksToDisplay, $displayArrows, $additionalQuery));
HTML Output
<ul class="pagination"> <li><a href="/results.php?search=Hello&important_info=42&page=1" title="Page 1">1</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=2" title="Page 2">2</a></li> <li class="active"><a href="/results.php?search=Hello&important_info=42&page=3" title="Page 3">3</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=4" title="Page 4">4</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=5" title="Page 5">5</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=6" title="Page 6">6</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=7" title="Page 7">7</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=8" title="Page 8">8</a></li> <li><a href="/results.php?search=Hello&important_info=42&page=9" title="Page 9">9</a></li> </ul>
adamb/pagination 适用场景与选型建议
adamb/pagination 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.25k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 adamb/pagination 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adamb/pagination 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 17
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-26