Skip to content

Commit 152c3f0

Browse files
committed
Initial Commit
0 parents  commit 152c3f0

File tree

5 files changed

+944
-0
lines changed

5 files changed

+944
-0
lines changed

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 benhall14
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# PHP Pagination
2+
A lightweight PHP pagination class to output pagination links.
3+
4+
This class is written to be chain-able so to create a logically fluent and easily readable way to create a set of pagination links.
5+
6+
It simplifies the paging of results and outputs Bootstrap 4 compatible navigation HTML.
7+
8+
It has been fully tested to work with PHP 5.5+, including **PHP 7+**
9+
10+
# Installation via Composer
11+
You can now install this class via composer.
12+
13+
$ composer require benhall14/php-pagination
14+
15+
**Remember** to add the composer autoloader before using the class and use the correct namespace.
16+
17+
require 'vendor/autoload.php';
18+
19+
use benhall14\PHPPagination\Pagination as Pagination;
20+
21+
# Usage
22+
Please make sure you have added the required classes.
23+
24+
In its simplest form, you can use the following to set up the paginator.
25+
26+
```php
27+
$pagination = new Pagination();
28+
$pagination->total(100)->output();
29+
```
30+
31+
You can use the following chainable methods to customise the final pagination links.
32+
```php
33+
# sets the total number of items in the collection - e.g. 100
34+
$pagination->total(number);
35+
36+
# sets the current page. By default, the class looks for the page value in the GET query string.
37+
$pagination->page(number);
38+
39+
# sets the number of items to show per page. Default = 20
40+
$pagination->perPage(number);
41+
42+
# sets the separator (if using). Default '...'
43+
$pagination->separator(text);
44+
45+
# sets the screen reader class. Default 'true', but you may need to set it to false if you are using your own custom css.
46+
$pagination->screenReader(bool);
47+
48+
# sets the Bootstrap 4 pagination link class to small
49+
$pagination->small();
50+
51+
# sets the Bootstrap 4 pagination link class to medium
52+
$pagination->medium();
53+
54+
# sets the Bootstrap 4 pagination link class to large
55+
$pagination->large();
56+
57+
# sets the Bootstrap 4 alignment class to left
58+
$pagination->alignLeft();
59+
60+
# sets the Bootstrap 4 alignment class to center
61+
$pagination->alignCenter();
62+
63+
# sets the Bootstrap 4 alignment class to right
64+
$pagination->alignRight();
65+
66+
# sets the flag to show the separator
67+
$pagination->showSeparator();
68+
69+
# sets the flag to hide the separator
70+
$pagination->hideSeparator();
71+
72+
# sets the next text string - Default: 'Next'
73+
$pagination->nextText(text);
74+
75+
# sets the previous text string - Default: 'Previous'
76+
$pagination->previousText(text);
77+
78+
# hides the 'Next' link
79+
$pagination->hideNext();
80+
81+
# shows the 'Next' link
82+
$pagination->showNext();
83+
84+
# hides the 'Previous' link
85+
$pagination->hidePrevious();
86+
87+
# shows the 'Previous' link
88+
$pagination->showPrevious();
89+
90+
# sets a prefix text for each page link: {prefix} {page number} {suffix}
91+
$pagination->pagePrefix(text);
92+
93+
# sets a suffix text for each page link: {prefix} {page number} {suffix}
94+
$pagination->pageSuffix(text);
95+
96+
# sets the flag to retain the query string for each page link.
97+
$pagination->retrainQueryString();
98+
99+
# sets the flag to ignore the query string when building the links
100+
$pagination->dismissQueryString();
101+
102+
# sets the number of pages BEFORE the separator
103+
$pagination->pagesBeforeSeparator(number);
104+
105+
# sets the number of pages AROUND the active page
106+
$pagination->pagesAroundActive(number);
107+
108+
# sets the URL pattern - Default $pattern: ?page=(:num)- $replacement: (:num)
109+
$pagination->pattern($pattern, $replacement);
110+
# The class will replace the $replacement token in the $pattern with the actual page number
111+
```
112+
113+
# Requirements
114+
115+
**Works with PHP 5.5, PHP 5.6, and PHP 7+**
116+
117+
# License
118+
Copyright (c) 2016-2019 Benjamin Hall, ben@conobe.co.uk
119+
https://conobe.co.uk
120+
121+
Licensed under the MIT license
122+
123+
# Donate?
124+
125+
If you find this project helpful or useful in any way, please consider getting me a cup of coffee - It's really appreciated :)
126+
127+
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/benhall14)

composer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "benhall14/php-pagination",
3+
"description": "A lightweight PHP pagination class to output pagination links.",
4+
"homepage": "https://github.com/benhall14/php-pagination",
5+
"keywords": ["php", "pagination", "paginate"],
6+
"license": "MIT",
7+
"type": "library",
8+
"authors": [
9+
{
10+
"name": "Benjamin Hall",
11+
"email": "ben@conobe.co.uk",
12+
"homepage": "https://conobe.co.uk",
13+
"role": "Developer"
14+
}
15+
],
16+
"require": {
17+
"php": ">=5.5"
18+
},
19+
"autoload": {
20+
"psr-4": {
21+
"benhall14\\": "src/"
22+
}
23+
}
24+
}

example.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
// either 'require' the class or use autoload
4+
require 'vendor/autoload.php';
5+
6+
// set namespace
7+
use benhall14\PHPPagination\Pagination as Pagination;
8+
9+
// add bootstrap css
10+
echo '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">';
11+
12+
// instaniate the class
13+
$pagination = new Pagination();
14+
15+
// set the config options and output
16+
$pagination->total(100)->output();

0 commit comments

Comments
 (0)