OhPage is a paginating library for PHP

1.0.0 2015-09-02 21:07 UTC

This package is auto-updated.

Last update: 2024-12-16 01:30:12 UTC


README

OhPage is a simple cheat, really it's because I'm tired of figuring out the skip / limit for paginating result sets.

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

Using Composer

To use OhPage with Composer, add the dependency (and version constraint) to your require block inside your composer.json file.

{
    "require": {
        "rogerthomas84/ohpage": "1.0.*"
    }
}

Quick Start

<?php
$db = new \MongoClient('mongodb://my.database.host:27017'); // Set up your database connection
$collection = $db->selectCollection('mydb', 'mycollection');

$perPage = 10; // How many results per page?
$currentPage = 1; // The current page
$totalResults = $collection->count(); // Get the total from the DB

$instance = new PaginateHelper($perPage, $currentPage, $totalResults);

$results = $collection->find()->sort(
    array('createdDate' => -1)
)->skip(
    $instance->getQueryOffset()
)->limit(
    $instance->getQueryLimit()
);