Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jasongrimes/php-paginator
A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr.
https://github.com/jasongrimes/php-paginator
Last synced: about 1 month ago
JSON representation
A lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr.
- Host: GitHub
- URL: https://github.com/jasongrimes/php-paginator
- Owner: jasongrimes
- License: mit
- Created: 2014-09-28T02:49:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-15T22:51:08.000Z (about 3 years ago)
- Last Synced: 2024-05-09T07:18:25.898Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 158 KB
- Stars: 378
- Watchers: 31
- Forks: 114
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-php - php-paginator - 分页处理类 (其他( Miscellaneous ))
- awesome-php - php-paginator - 分页处理类 (URL)
- awesome-php - php-paginator - 分页处理类 (其他( Miscellaneous ))
README
PHP Paginator
=============[![Build Status](https://travis-ci.org/jasongrimes/php-paginator.svg?branch=master)](https://travis-ci.org/jasongrimes/php-paginator)
[![Total Downloads](https://poser.pugx.org/jasongrimes/paginator/downloads.svg)](https://packagist.org/packages/jasongrimes/paginator)
[![Latest Stable Version](https://poser.pugx.org/jasongrimes/paginator/v/stable.svg)](https://packagist.org/packages/jasongrimes/paginator) [![Latest Unstable Version](https://poser.pugx.org/jasongrimes/paginator/v/unstable.svg)](https://packagist.org/packages/jasongrimes/paginator) [![License](https://poser.pugx.org/jasongrimes/paginator/license.svg)](https://packagist.org/packages/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.
## Screenshots
These examples show how the paginator handles overflow when there are a lot of pages.
They're rendered using the sample templates provided in the [examples](examples/) directory,
which depend on Twitter Bootstrap.
You can easily use your own custom HTML to render the pagination control instead.Default template:
Small template (useful for mobile interfaces):
The small template renders the page number as a select list to save space:
## Installation
Install with composer:
composer require "jasongrimes/paginator:~1.0"
## Basic usage
Here's a quick example using the defaults:
This will output the following:
To render it with one of the other example templates, just make sure the variable is named `$paginator` and then include the template file:
$paginator = new Paginator($totalItems, $itemsPerPage, $currentPage, $urlPattern);
include '../vendor/jasongrimes/paginator/examples/pagerSmall.phtml';
If the example templates don't suit you, you can iterate over the paginated data to render your own pagination control.
## Rendering a custom pagination control
Use `$paginator->getPages()`, `$paginator->getNextUrl()`, and `$paginator->getPrevUrl()` to render a pagination control with your own HTML.
For example:
- « Previous
- >
- Next »
getPrevUrl()): ?>
getPages() as $page): ?>
getNextUrl()): ?>
getTotalItems(); ?> found.
Showing
getCurrentPageFirstItem(); ?>
-
getCurrentPageLastItem(); ?>.
See the [examples](examples) directory for more sample templates.
## Pages data structure
$paginator->getPages();
`getPages()` returns a data structure like the following:
array (
array ('num' => 1, 'url' => '/foo/page/1', 'isCurrent' => false),
array ('num' => '...', 'url' => NULL, 'isCurrent' => false),
array ('num' => 5, 'url' => '/foo/page/5', 'isCurrent' => false),
array ('num' => 6, 'url' => '/foo/page/6', 'isCurrent' => false),
array ('num' => 7, 'url' => '/foo/page/7', 'isCurrent' => false),
array ('num' => 8, 'url' => '/foo/page/8', 'isCurrent' => true),
array ('num' => 9, 'url' => '/foo/page/9', 'isCurrent' => false),
array ('num' => 10, 'url' => '/foo/page/10', 'isCurrent' => false),
array ('num' => 11, 'url' => '/foo/page/11', 'isCurrent' => false),
array ('num' => 12, 'url' => '/foo/page/12', 'isCurrent' => false),
array ('num' => '...', 'url' => NULL, 'isCurrent' => false),
array ('num' => 20, 'url' => '/foo/page/20', 'isCurrent' => false),
)
## Customizing the number of pages shown
By default, no more than 10 pages are shown, including the first and last page, with the overflow replaced by ellipses.
To change the default number of pages:
$paginator->setMaxPagesToShow(5);