PHPackages                             hizpark/paginator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hizpark/paginator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hizpark/paginator
=================

Flexible pagination utility for PHP applications

v1.0.0(10mo ago)00MITPHPPHP &gt;=8.2CI passing

Since Sep 3Pushed 10mo agoCompare

[ Source](https://github.com/changhorizon/paginator)[ Packagist](https://packagist.org/packages/hizpark/paginator)[ RSS](/packages/hizpark-paginator/feed)WikiDiscussions main Synced 2mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Paginator
=========

[](#paginator)

> PHP pagination made easy

[![License](https://camo.githubusercontent.com/bada797127f2e745612a79932f8bbea190ce8cf4a8f27a937d194de6c0f47713/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68697a7061726b2f706167696e61746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/bada797127f2e745612a79932f8bbea190ce8cf4a8f27a937d194de6c0f47713/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68697a7061726b2f706167696e61746f723f7374796c653d666c61742d737175617265)[![Latest Version](https://camo.githubusercontent.com/1f2068fd25ed144e0025d19281998d9a17104950717fecf85b09e90bd98283a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68697a7061726b2f706167696e61746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1f2068fd25ed144e0025d19281998d9a17104950717fecf85b09e90bd98283a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68697a7061726b2f706167696e61746f723f7374796c653d666c61742d737175617265)[![PHP Version](https://camo.githubusercontent.com/10b897c523f00fa3f8f7b54dfe73999190e622480655d5b5f011e31fc32a7111/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322d2d382e342d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/10b897c523f00fa3f8f7b54dfe73999190e622480655d5b5f011e31fc32a7111/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322d2d382e342d626c75653f7374796c653d666c61742d737175617265)[![Static Analysis](https://camo.githubusercontent.com/1a477f5e7e742a33c1ff5b685167579083a26c342c4e997fe056ea4ef7bea73e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617469635f616e616c797369732d5048505374616e2d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1a477f5e7e742a33c1ff5b685167579083a26c342c4e997fe056ea4ef7bea73e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374617469635f616e616c797369732d5048505374616e2d626c75653f7374796c653d666c61742d737175617265)[![Tests](https://camo.githubusercontent.com/72829871c802983bff15745f71c846973b36a6fea0bb5298dadaeeb690463604/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e69742d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/72829871c802983bff15745f71c846973b36a6fea0bb5298dadaeeb690463604/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d504850556e69742d627269676874677265656e3f7374796c653d666c61742d737175617265)[![codecov](https://camo.githubusercontent.com/0aba765c7506de2ead682ca878fb9dbed54ac9d4479a776418259821fa6aeec4/68747470733a2f2f636f6465636f762e696f2f67682f68697a7061726b2f706167696e61746f722f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/hizpark/paginator)[![CI](https://github.com/hizpark/paginator/actions/workflows/ci.yml/badge.svg?style=flat-square)](https://github.com/hizpark/paginator/actions/workflows/ci.yml/badge.svg?style=flat-square)

Flexible pagination for PHP applications.

✨ 特性
----

[](#-特性)

- Calculate total pages, current page, previous and next pages.
- Generate page numbers for navigation with ellipsis support.
- Provides query limits and offsets for database queries.
- Handles edge cases like first page, last page, and single-page scenarios.
- Fully typed and compatible with PHP 8+.

📦 安装
----

[](#-安装)

```
composer require hizpark/paginator
```

📂 目录结构
------

[](#-目录结构)

```
src
└── Paginator.php
```

🚀 用法示例
------

[](#-用法示例)

### 示例 1：基础分页导航

[](#示例-1基础分页导航)

```
use Hizpark\Paginator\Paginator;

// 假设总共有 120 条记录，每页 10 条，当前在第 5 页
$paginator = new Paginator(totalRows: 120, pageSize: 10, pageNumber: 5);

// 当前页码
echo $paginator->currentPage(); // 5

// 总页数
echo $paginator->totalPages(); // 12

// 上一页 / 下一页
echo $paginator->prevNumber(); // 4
echo $paginator->nextNumber(); // 6

// 页码数组（用于显示分页导航）
print_r($paginator->pageNumbers());
// 输出示例: [1, '…', 4, 5, 6, '…', 12]
```

### 示例 2：结合数据库查询分页

[](#示例-2结合数据库查询分页)

```
use Hizpark\Paginator\Paginator;
use PDO;

// 假设数据库有 120 条记录，每页 10 条，当前第 3 页
$totalRows  = 120;
$pageSize   = 10;
$pageNumber = 3;

$paginator = new Paginator($totalRows, $pageSize, $pageNumber);

// PDO 查询示例
$pdo = new PDO('mysql:host=localhost;dbname=testdb', 'user', 'pass');
$stmt = $pdo->prepare('SELECT * FROM posts LIMIT :limit OFFSET :offset');
$stmt->bindValue(':limit', $paginator->limitForQuery(), PDO::PARAM_INT);
$stmt->bindValue(':offset', $paginator->offsetForQuery(), PDO::PARAM_INT);
$stmt->execute();

$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

// 打印结果
print_r($rows);
```

🔍 静态分析
------

[](#-静态分析)

使用 PHPStan 工具进行静态分析，确保代码的质量和一致性：

```
composer stan
```

🎯 代码风格
------

[](#-代码风格)

使用 PHP-CS-Fixer 工具检查代码风格：

```
composer cs:chk
```

使用 PHP-CS-Fixer 工具自动修复代码风格问题：

```
composer cs:fix
```

✅ 单元测试
------

[](#-单元测试)

执行 PHPUnit 单元测试：

```
composer test
```

执行 PHPUnit 单元测试并生成代码覆盖率报告：

```
composer test:coverage
```

🤝 贡献指南
------

[](#-贡献指南)

欢迎 Issue 与 PR，建议遵循以下流程：

1. Fork 仓库
2. 创建新分支进行开发
3. 提交 PR 前请确保测试通过、风格一致
4. 提交详细描述

📜 License
---------

[](#-license)

MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance55

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

303d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/191742660?v=4)[ChangHorizon](/maintainers/changhorizon)[@changhorizon](https://github.com/changhorizon)

---

Tags

helperutilitypaginatorpaginationnavigationpage numbers

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hizpark-paginator/health.svg)

```
[![Health](https://phpackages.com/badges/hizpark-paginator/health.svg)](https://phpackages.com/packages/hizpark-paginator)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k430.4M1.7k](/packages/nette-utils)[jasongrimes/paginator

A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

4091.3M22](/packages/jasongrimes-paginator)[coffeecode/paginator

Paginator is simple and is ready to generate results navigation in your application

59660.6k1](/packages/coffeecode-paginator)[beberlei/porpaginas

Library that generically solves several pagination issues with DAO/repository abstractions.

163643.5k14](/packages/beberlei-porpaginas)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38427.7k](/packages/bocharsky-bw-arrayzy)[stefangabos/zebra_pagination

A generic, Twitter Bootstrap compatible, PHP pagination library that automatically generates navigation links

11923.8k](/packages/stefangabos-zebra-pagination)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
