Download the PHP package salernolabs/pagination without Composer

On this page you can find all versions of the php package salernolabs/pagination. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pagination

salernolabs/pagination

Latest Stable Version License Build Status

A simple library that wraps some common pagination stuff and can build bootstrap HTML. Yes I know a billion of these exist, I've been offloading old code into individual tested libraries for organization purposes as I move some sites over to Symfony. I may add more formatters at some point, I've been playing with material ui as well, but its not here yet. PR's welcome.

Installation

composer require salernolabs/pagination

How to Use

The idea is to build a pagination object (base or formatted), input some values, retrieve all the pagination info plus html you want.

Base Pagination Class

The constructor takes several optional arguments. They can also be set with set* methods.

$p = new \SalernoLabs\Pagination\Pagination(
  $pageNumber,
  $numberOfItemsPerPage,
  $totalItems
);

Get all the calculated pagination data with $p->getPaginationData();

PageData Response Class

The ->getPaginationData() method will return the PageData response object. The following methods are available on this object:

Method Return Type Info
getPageNumber() int The current page number, unless it exceeds calculated total pages in which case the last page number is returned.
getTotalItems() int The total number of items, this is what you originally entered
getItemsPerPage() int The total number of items per page, this is what you originally entered.
getOffset() int The calculated database row offset value, suitable for queries
getTotalPages() int The calculated total number of pages

BootstrapHTML Generator

The Bootstrap library.

->generateOutput($paginationUrl, $pageNumberConstant, $additionalUrlData)

This method will generate the output for you using the input parameters to format the urls. If your paginated URLs are of the format /news/1 for page 1, /news/2 etc, your first parameter would be '/news/#'.

If your URL format is more like '/articles/index?pageNumber=44' you could do '/articles/index?pageNumber=#'

If you need to change the value # in the url template, the second parameter can change it.

Finally the third parameter just adds extra stuff to the end of your URLs.

Usage Example

$articleCount = /* query article count */ 500;

$pagination = new \SalernoLabs\Pagination\Formatter\BootstrapHTML();
$pagination
    ->setPageNumber(1)
    ->setNumberOfItemsPerPage(20)
    ->setTotalItems($articleCount);
$page = $pagination->getPaginationData();

// eg. LIMIT $page->getOffset(), $page->getItemsPerPage()

$paginationHTML = $pagination->generateOutput('/news/#', '#');

At this point you should have the HTML you need to output.

Customizing the HTML

There are some extra methods in formatters to tweak the output of the HTML. They are as follows:

Method Default Info
setNextButton() › Sets the text for the "next" button.
setPreviousButton() ‹ Sets the text for the "previous" button.
setFirstButton() « Sets the text for the "first" button.
setLastButton() » Sets the text for the "last" button.
setSpace()   Sets the string to use for spaces.
setItemStride() 5 Sets the stride, basically controls the number of number buttons. A value of five would show five before the current value and five including and after the current value for a total of 10.

Testing

Testing is just PHPunit. Example build with coverage report if you've loaded composer dev dependencies:

php vendor/phpunit/phpunit/phpunit --coverage-html build/coverage-report

We aimed for 100% coverage in version 1.#


All versions of pagination with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package salernolabs/pagination contains the following files

Loading the files please wait ...