|
| 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 | +[](https://paypal.me/benhall14) |
0 commit comments