php-pagination / php-pagination
PHP Pagination Class with 4 types: Simple Pagination, Google Pagination, Digg/PHPBB Pagination Style.
Installs: 11 224
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: 5.5.*
This package is auto-updated.
Last update: 2024-10-29 05:04:59 UTC
README
PHP paging class with 4 different page types:
Simple Pagination:
Creates a simple pagination similar to Google.PHPBB/Digg Pagination:
Paging in the same style as the PHPBB CMS/Digg. In addition to the normal pages you have the markers with the last pages and home pages.Jumping Pagination:
Paging where the markers "jump" after a certain value, for example: Every 10 page markers are displayed from 1 to 10 - 11 to 20 - 21 to 30 and so on.Google Pagination:
PHP paging is the same as that used by Google to display search results.
See the examples folder for using the class easily.
Features
v2.0.1
Added method to get start for sql clauses.v2.0.0
The methods were refactored, unit tests added, examples and design patters.
Important informations
-
You need PHP 7.0 or higher to use this class.
-
I used the strategy pattern to create different pagination types. I put the examples in the examples folder. This pagination returns only one PHP ArrayObject, so you create the layout part as you wish.
-
The pagination always returns the first page, last page, previous, next, an ArrayObject with total pages, 2 methods to advance or retreat a deternated number of pages and finally another ArrayObject with the markers following the paging style logic chosen.
-
This is a free project, feel free to use it in your projects, even if they are commercial. You can also contribute tips, new features and fixes.
Example of use
To use this class you must follow the code below. Do not forget to access the examples folder here in the repository with the usage examples for each page type. Also access rafaacademy.com for tips and tutorials on php and use of this class.
Install: composer require php-pagination/php-pagination
<?php require '../vendor/autoload.php'; use Pagination\Pagination; use Pagination\StrategySimple; if ( isset($_GET['page']) && is_numeric($_GET['page']) ) $page = $_GET['page']; else $page = 1; //use pagination class with results, per page and page $pagination = new Pagination(1000, 10, $page); //get first page $pagination->getFirstPage(); //get last page $pagination->getLastPage(); //get previous page $pagination->getPreviousPage(); //get next page $pagination->getNextPage(); //get all indexes $all = $pagination->getAllIndexesOfPages(); $iteratorAll = $all->getIterator(); //get indexes in page stylized $indexes = $pagination->getIndexes(new StrategySimple(15)); $iterator = $indexes->getIterator(); //get start for sql queries (optional - Note: This paging does not use a bank connection) $pagination->getStartForSqlQueries();
To navigate between indexes you need to learn how to work with the ArrayInterator and ArrayObject of PHP.