iu-vpcm / rivet2-pagination
用于生成IU Rivet v2分页的库
v1.0
2022-05-11 16:24 UTC
Requires
- phpunit/phpunit: ^9.5.18
README
嗯,名字已经说明了一切。希望这个库能帮助您简化生活。
如果需要Rivet V1和V2分页的更多详细信息
安装
两种方式:使用 Composer,或者直接 include/require
Composer
在您的composer项目根目录下运行以下命令,其中包含composer.json。
composer require iu-vpcm/rivet2-pagination
纯PHP include/require
下载脚本,并将其命名为您想要的名称(例如 rivet_pagination.php),然后在您的脚本中
require 'PATH-TO/rivet_pagination.php'; // or // inlcude 'PATH-TO/rivet_pagination.php'
使用方法
基本
注意: 如果在$options['rivetVersion']中未指定,库将生成Rivet V2分页。
唯一必需的参数是需要分页的项目数量。
以下列出了其他参数,如每页的项目数量,以及$_GET中的键,表示当前页码,并带有它们的默认值
/** * protected $pageKeyInGet = 'page'; * protected $queryString = $_SERVER['QUERY_STRING]; * protected $perPage = 9; * protected $paginationLength = 5; * protected $rivetVersion = 2; */ $totalNumItems = 100; $pagination = new Pagination($totalNumItems); echo $pagination->render();
高级
V1分页
// not required $v1Settings = [ 'position' => 'center', // or 'right' 'size' => 'small' ]; $options = [ 'rivetVersion' => 'v1', // required if V1 pagination is desired 'rivetV1Settings' => $v1Settings // it not set or empty, default style of V1 will be applied ]; $pagination = new \Edu\IU\VPCM\Rivet\Pagination(150, $options); echo $pagination->render();
设置分页长度/宽度
/** * default * protected $paginationLength = 5; */ $totalNumItems = 100; $options = ['paginationLength' => 10] $pagination = new Pagination($totalNumItems, $options); echo $pagination->render();
设置每页显示的项目数量
/** * default * protected $perPage = 9; */ $totalNumItems = 100; $options = ['perPage' => 10] $pagination = new Pagination($totalNumItems, $options); echo $pagination->render();
设置$_GET中的哪个键表示页码
/** * default * protected $pageKeyInGet = 'page'; */ $totalNumItems = 100; $options = ['pageKeyInGet' => 'myPage'] $pagination = new Pagination($totalNumItems, $options); echo $pagination->render();
如果需要自定义查询字符串
/** * default * protected $queryString = $_SERVER['QUERY_STRING]; */ $totalNumItems = 100; $options = ['queryString' => '?tom=jerry&mj=forever'] // the '?' can be omitted $pagination = new Pagination($totalNumItems, $options); echo $pagination->render();