dev-master
9999999-devPagination library without dependencies.
MIT
The Requires
- php >=5.6
The Development Requires
by Dennis Meckel
pagination paginator filter-pagination search-pagination
Pagination library without dependencies.
Pagination library without dependencies., (*1)
It's recommended to use the dependency manager
Composer
to install rayne/pagination
., (*2)
composer require rayne/pagination
Implementation of the Search Pagination Pattern defined by Yahoo, (*3)
One or zero indexed pages, (*4)
Extracts safe page numbers from arbitrary user inputs, e.g. first or last page on invalid input or when being out of bounds, (*5)
Implementation of the Filter Pagination Pattern defined by Yahoo, (*6)
(This pattern is currently not officially supported but the code is ready for playing around), (*7)
No dependencies (except the ones for testing), (*8)
Framework-agnostic, (*9)
No markup (but Bootstrap examples in /examples
), (*10)
No template engine (but Twig examples in /examples
), (*11)
No database backend (but offset and limit provided), (*12)
No URL builder, (*13)
Retrieve item count $totalItems
, (*14)
Let Rayne\Pagination
calculate the offset, (*15)
$pagination = new SearchPagination( $totalItems, $itemsPerPage, $currentPage, $pagePadding = 4, $isZeroBased = false );
Verify $currentPage
with $pagination->isOnValidPage()
or retrieve the requested items with the help of $pagination->getItemOffset()
and $pagination->getItemLimit()
, (*16)
Render results and controls with the help of $pagination
or $pagination->toArray()
and the example templates in the /examples
directory, (*17)
Read the Examples section for examples and ideas., (*18)
Instead of creating the SearchPaginationInterface
implementation by hand
a configurable factory can be used to provide the pagination as a service., (*19)
Either create a new factory (useful when working with a DI system) …, (*20)
$factory = new SearchPaginationFactory;
… or initialize/fetch the global one, (*21)
$factory = SearchPaginationFactory::instance();
The defaults are: one-indexed pages, 20
items per page and a page padding of 4
., (*22)
Configure the factory (or skip this step), (*23)
$factory->setIsZeroBased(true); $factory->setItemsPerPage(25); $factory->setPagePadding(2);
Build a new SearchPagination
object, (*24)
$totalItems = 123; $currentPage = 2; $pagination = $factory->build($totalItems, $currentPage);
The filter pagination pattern is not officially supported but feel free to play around with the following classes:, (*25)
Rayne\Pagination\Filter\FilterPage Rayne\Pagination\Filter\FilterPages Rayne\Pagination\Filter\FilterPagination
The following examples are part of the /examples
directory., (*26)
Complete example (/examples/index.php
), (*27)
Simple (highlights current page) and advanced (highlights current page, hides redundant pagination controls) examples, (*28)
PHP snippets (/examples/PHP
), (*29)
Twig macros (/examples/Twig
), (*30)
The Twig macros are Bootstrap Framework compatible, (*31)
Clone the repository, (*32)
git clone https://github.com/rayne/pagination.git
Install the development dependencies, (*33)
composer install --dev
Run the tests, (*34)
composer test
Pagination library without dependencies.
MIT
pagination paginator filter-pagination search-pagination