forrest79/pagination

创建具有对数尺度、相邻页面或所有页面的分页页面列表。

v0.3.0 2023-09-17 16:21 UTC

This package is auto-updated.

Last update: 2024-09-13 20:33:16 UTC


README

Latest Stable Version Monthly Downloads License Build

创建具有对数尺度、相邻页面或所有页面的分页页面列表。

算法复制自 https://github.com/nikolassv/pagination

安装

推荐通过 Composer 安装 Forrest79/Pagination

composer require forrest79/pagination

如何使用它

只需使用 PagesFactory:: 并传入你想要的页面列表

$pages = Forrest79\Pagination\PagesFactory::all(100);
$pages = Forrest79\Pagination\PagesFactory::neighbour(100, 1, 5);
$pages = Forrest79\Pagination\PagesFactory::logarithmic(100, 10, 10);

你将得到一个排序后的 array,其中包含 integer 页面编号。对于相邻和对数尺度,在损坏的页面系列位置也有 NULL 值,例如:[1, 2, 3, NULL, 7, 8]。所以你知道在哪里打印空格。你可以通过将参数 $addGaps 设置为 FALSE 来禁用此行为。

Nette 示例

使用默认分页器进行简单使用

class Paginator extends Nette\Utils\Paginator
{

	public function pages(): array
	{
		if ($this->getPageCount() === NULL) {
			throw new InvalidArgumentException('We need page count set to generate pages list');
		}
		return Forrest79\Pagination\PagesFactory::logarithmic($this->getPageCount(), $this->getPage(), 10);
	}

}

latte

<li n:foreach="$paginator->pages() as $page" n:class="$page === $paginator->getPage() ? active, $page === NULL ? disabled">
	{if $page === NULL}
		..
	{else}
		<a n:href="this, page => $page">{$page}</a>
	{/if}
</li>