centralapps/pagination

A pagination library which interacts with PDO

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.0.2 2017-02-28 16:57 UTC

This package is not auto-updated.

Last update: 2020-01-20 03:51:53 UTC


README

A set of classes which compliment and extend the PHP PDO library to provide support for pagination.

Build Status Total Downloads

This is a beta release, and subject to change, however it is functional.

TODO: Investigate using \PDO::ATTR_STATEMENT_CLASS in prepare method calls instead to reduce the complexity of the project.

Installation (with composer)

Add

"centralapps/pagination": "v1.0.0"

To your composer.json file, then install

php composer.phar update

## Usage

Create a pagination object to represent the current page

$pagination = new \CentralApps\Pagination\Pagination();
$pagination->setMaxResultsPerPage(25);
$pagination->setCurrentPageNumber(1);

Instantiate the extended Pdo class

$pdo = new \CentralApps\Pagination\Pdo(...)

If you already have an extended Pdo class, the functionality is available within the PdoTrait class; though this is likely to change as functionality is migrated into the statement.

Call prepareWithPagination, passing the pagination object as the second parameter (driver options is available as the third parameter)

$statement = $pdo->prepareWithPagination($sql, $pagination);

The resulting statement is special. It contains within it, the statement for the paginated query, and a statement which counts the total number of applicable records (to calculate page numbers). Bindings to the statement apply to both statements, and upon execution, both statements are executed, the resulting page number stored within itself. Calling getPaginationWithTotalCount on the statement post-execution returns the original pagination object, with total number of results. This can be used to generate a pagination nav-bar.