benhall14 / php-pagination
一个轻量级的PHP分页类,用于输出分页链接。
1.1
2019-08-07 21:16 UTC
Requires
- php: >=5.5
This package is auto-updated.
Last update: 2024-09-26 15:54:50 UTC
README
一个轻量级的PHP分页类,用于输出分页链接。
这个类是为了能够链式调用而编写的,以创建一组逻辑清晰且易于阅读的分页链接。
它简化了结果分页,并输出与Bootstrap 4兼容的导航HTML。
它已完全测试,可在PHP 5.5+上运行,包括 PHP 7+
通过Composer安装
现在您可以通过composer安装此类。
$ composer require benhall14/php-pagination
请记住在使用此类之前添加composer自动加载器,并使用正确的命名空间。
require 'vendor/autoload.php';
use benhall14\PHPPagination\Pagination as Pagination;
用法
请确保您已添加所需的类。
在其最简单形式中,您可以使用以下方式设置分页器。
$pagination = new Pagination(); $pagination->total(100)->output();
您可以使用以下链式方法来自定义最终的分页链接。
# sets the total number of items in the collection - e.g. 100 $pagination->total(number); # sets the current page. By default, the class looks for the page value in the GET query string. $pagination->page(number); # sets the number of items to show per page. Default = 20 $pagination->perPage(number); # sets the separator (if using). Default '...' $pagination->separator(text); # sets the screen reader class. Default 'true', but you may need to set it to false if you are using your own custom css. $pagination->screenReader(bool); # sets the Bootstrap 4 pagination link class to small $pagination->small(); # sets the Bootstrap 4 pagination link class to medium $pagination->medium(); # sets the Bootstrap 4 pagination link class to large $pagination->large(); # sets the Bootstrap 4 alignment class to left $pagination->alignLeft(); # sets the Bootstrap 4 alignment class to center $pagination->alignCenter(); # sets the Bootstrap 4 alignment class to right $pagination->alignRight(); # sets the flag to show the separator $pagination->showSeparator(); # sets the flag to hide the separator $pagination->hideSeparator(); # sets the next text string - Default: 'Next' $pagination->nextText(text); # sets the previous text string - Default: 'Previous' $pagination->previousText(text); # hides the 'Next' link $pagination->hideNext(); # shows the 'Next' link $pagination->showNext(); # hides the 'Previous' link $pagination->hidePrevious(); # shows the 'Previous' link $pagination->showPrevious(); # sets a prefix text for each page link: {prefix} {page number} {suffix} $pagination->pagePrefix(text); # sets a suffix text for each page link: {prefix} {page number} {suffix} $pagination->pageSuffix(text); # sets the flag to retain the query string for each page link. $pagination->retainQueryString(); # sets the flag to ignore the query string when building the links $pagination->dismissQueryString(); # sets the number of pages BEFORE the separator $pagination->pagesBeforeSeparator(number); # sets the number of pages AROUND the active page $pagination->pagesAroundActive(number); # sets the URL pattern - Default $pattern: ?page=(:num)- $replacement: (:num) $pagination->pattern($pattern, $replacement); # The class will replace the $replacement token in the $pattern with the actual page number
要求
支持PHP 5.5、PHP 5.6和PHP 7+
许可证
版权(c)2016-2019 Benjamin Hall,ben@conobe.co.uk https://conobe.co.uk
在MIT许可证下发布
捐赠?
如果您觉得这个项目在某种程度上对您有帮助或有价值,请考虑给我买杯咖啡 - 真的是非常感谢 :)