sirprize/paginate
Composer 安装命令:
composer require sirprize/paginate
包简介
Normalize an index range from user input
关键字:
README 文档
README
Normalize an index range from user input
Use Case 1 (start with an index range)
- Get the current range from user input (eg from a HTTP header -
Range: items=40-49) - Define the slice (eg run a query with a
LIMITexpression)
Usage
use Sirprize\Paginate\Input\IndexInput;
use Sirprize\Paginate\Range\IndexRange;
$i = new IndexInput(4400, 4499); // $offset, $last
$i->setDefaultNumItems(25)->setMaxItems(100); // set defaults and limits
$r = new IndexRange($i);
$q = sprintf("SELECT * FROM my_table LIMIT %d, %d", $r->getOffset(), $r->getNumItems());
Use Case 2 (start from current page)
- Get the current page and possibly the number of items per page from user input
- Define the slice (eg run a query with a
LIMITexpression)
Usage
use Sirprize\Paginate\Input\PageInput;
use Sirprize\Paginate\Range\PageRange;
$i = new PageInput(45, 100); // $currentPage, $numItemsPerPage
$i->setDefaultNumItems(25)->setMaxItems(100); // set defaults and limits
$r = new PageRange($i);
$q = sprintf("SELECT * FROM my_table LIMIT %d, %d", $r->getOffset(), $r->getNumItems());
Paginator
- Perform an action to get the total number of items in a list (eg run a simple query with a
COUNTexpression) - Get the current page and possibly the number of items per page from user input
- Start paginator with user input and number of items
- Define the slice (eg run a complex query with a
LIMITexpression)
Usage
use Sirprize\Paginate\Input\PageInput;
use Sirprize\Paginate\Range\PageRange;
use Sirprize\Paginate\Paginator;
$i = new PageInput(45, 100); // $currentPage, $numItemsPerPage
$i->setDefaultNumItems(25)->setMaxItems(100); // set defaults and limits
$r = new PageRange($i);
$r->setTotalItems(189678);
$p = new Paginator($r);
$p->setBaseUrl('/products')
$p->setPageParam('p');
The following information is available:
echo $p->isOutOfBounds(); // 0
echo $p->getTotalItems(); // 189678
echo $p->getNumItemsPerPage(); // 100
echo $p->getNumItemsOnCurrentPage(); // 100
echo $p->getFirstItemOnCurrentPage(); // 4401
echo $p->getLastItemOnCurrentPage(); // 4500
echo $p->getNumPages(); // 1897
echo $p->getCurrentPage(); // 45
echo $p->getPreviousPage(); // 44
echo $p->getNextPage(); // 46
echo $p->getFirstPage(); // 1
echo $p->getLastPage(); // 1897
echo $p->getOffset(); // 4400
echo $p->getLast(); // 4499
echo $p->getCurrentPageUrl(); // /products?p=45
echo $p->getNextPageUrl(); // /products?p=46
echo $p->getPreviousPageUrl(); // /products?p=44
echo $p->getFirstPageUrl(); // /products?p=1
echo $p->getLastPageUrl(); // /products?p=1897
echo $p->getBaseUrl(); // /products
echo $p->getPageParam(); // p
License
See LICENSE.
sirprize/paginate 适用场景与选型建议
sirprize/paginate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 387 次下载、GitHub Stars 达 1, 最近一次更新时间为 2012 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pager」 「paginator」 「pagination」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sirprize/paginate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sirprize/paginate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sirprize/paginate 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine Collections adapter for Rekapager pagination library
Core functionality of Rekapager pagination library
Common classes for Symfony integration.
Symfony DataGridBundle
Symfony bundle for the Rekapager library
MongoDB Adapter to be used with Laminas Paginator
统计信息
- 总下载量: 387
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-05-17