定制 sirprize/paginate 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

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)

  1. Get the current range from user input (eg from a HTTP header - Range: items=40-49)
  2. Define the slice (eg run a query with a LIMIT expression)

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)

  1. Get the current page and possibly the number of items per page from user input
  2. Define the slice (eg run a query with a LIMIT expression)

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

  1. Perform an action to get the total number of items in a list (eg run a simple query with a COUNT expression)
  2. Get the current page and possibly the number of items per page from user input
  3. Start paginator with user input and number of items
  4. Define the slice (eg run a complex query with a LIMIT expression)

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-05-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固