PHPackages                             molajo/pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. molajo/pagination

ActiveMolajo-package[Utility &amp; Helpers](/categories/utility)

molajo/pagination
=================

Pagination Support for PHP Applications

0.1.0(12y ago)0590MITPHPPHP &gt;=5.4

Since Feb 1Pushed 10y ago3 watchersCompare

[ Source](https://github.com/Molajo/Pagination)[ Packagist](https://packagist.org/packages/molajo/pagination)[ Docs](http://github.com/Molajo/Pagination)[ RSS](/packages/molajo-pagination/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

======= Molajo Pagination
=========================

[](#molajo-pagination)

[![Build Status](https://camo.githubusercontent.com/f1028a27e6bc232638cff1d0a0a9a69a36fbbc435575588f5bc16873912a11ee/68747470733a2f2f7472617669732d63692e6f72672f4d6f6c616a6f2f506167696e6174696f6e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Molajo/Pagination)

Provides easy pagination data for any PHP application.

At a glance ...
---------------

[](#at-a-glance-)

1. Get the `page_url`, `query parameters` and `start` value from your preferred `Http Request Class.`
2. Run a query (or produce a list of items) using normal `offset` and `row limit` criteria.
3. Instantiate the `Molajo\Pagination` class, injecting it with the data and various pagination values.
4. Use the pagination data object to render the pagination interface.

Detailed Example
----------------

[](#detailed-example)

The following is from a working example of a Pagination View located in in the [.dev/Sample](https://github.com/Molajo/Pagination/tree/master/.dev/Sample) folder. To see the demo on your local website, create an Apache Host using [the Public Folder](https://github.com/Molajo/Pagination/tree/master/.dev/Sample/Public) as the Disk Location. Then, use the Server Name as the address in your browser.

```
/** 1. Routing: simulates the Router */
include __DIR__ . '/Route.php';

/** 2. Configuration Data */
include __DIR__ . '/RuntimeData.php';

/** 3. Get Mocked Data: could be any list of data */
include __DIR__ . '/MockData.php';

$data_instance = new \Molajo\Pagination\MockData(
    (int)$runtime_data->route->parameter_start,
    (int)$runtime_data->parameters->display_items_per_page_count
);

$mockdata = $data_instance->getData();

/** */
/** 4. Get Pagination Data (the main point!) */
/** */
$pagination_instance = new \Molajo\Pagination();

$row = $pagination_instance->getPaginationData(

// Configuration: variables your application must provide
    $runtime_data->parameters->display_items_per_page_count, // How many items are displayed on each page?
    $runtime_data->parameters->display_page_link_count, // 3 in this example =>  >>
    $runtime_data->parameters->create_sef_url_indicator, // Should SEF URLs be returned? true or false
    $runtime_data->parameters->display_index_in_url_indicator, // Should index.php appear in the URL? true or false

    // Primary Data: the total number of rows that could have been returned for the primary data
    $data_instance->getTotalItemsCount(),

    // Router: data from your router to help build the URLs for the pagination links
    $runtime_data->route->page, // URL for page on which paginated appears
    $runtime_data->route->parameter_start, // Query parameter 'start', for example, "?start=3" or "/start/3"
    array() // Other query parameters like "&tag=dog" or "/category/dog"
);
```

### Pagination Output

[](#pagination-output)

The Pagination `getPaginationData` method returns a data object of the following data elements that correspond to this mock-up of a rendered view.

```
   > >>
   A ... B. C........ D. E....

```

A `>`

- $row-&gt;last\_page\_number
- $row-&gt;last\_page\_link

Additional data provided by the method:

- $row-&gt;current\_start\_parameter\_number
- $row-&gt;current\_start\_parameter\_link
- $row-&gt;total\_items

### Example View

[](#example-view)

The following View is [part of the Example](https://github.com/Molajo/Pagination/blob/master/.dev/Sample/Views/Pagination.phtml)to demonstrate how to use the pagination data for rendering.

```

            &laquo; &laquo;
