Pagination - adampatterson/Dingo-Framework GitHub Wiki

###Overview The Pagination helper is designed to make it easier for you to paginate data in your application. To load the Pagination helper manually you may do this:

load::library('pagination');

###Basic Usage The pagination library takes 3 arguments.

  • resource (optional) - An array of data to be paginated or a number.
  • page - Current page. Default value is 1.
  • limit - limit of results per page. Default is 10.

Here is how you use it:

// Some data to paginate
$resource = array(
	array('id'=>1,'name'=>'Evan'),
	array('id'=>2,'name'=>'Joe'),
	array('id'=>3,'name'=>'Rick'),
	array('id'=>4,'name'=>'Mary'),
	array('id'=>5,'name'=>'Alice'),
	array('id'=>6,'name'=>'Ben'),
	array('id'=>7,'name'=>'Carly'),
	array('id'=>8,'name'=>'George'),
	array('id'=>9,'name'=>'Kara'),
	array('id'=>10,'name'=>'Harley'),
	array('id'=>11,'name'=>'Chester'),
	array('id'=>12,'name'=>'Louise'),
	array('id'=>13,'name'=>'Karl')
);

$page = new pagination($resource,1,5);

// Get rows for current page
$res = $page->results();

// Display results
print_r($res);

This will output:

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => Evan
        )

    [1] => Array
        (
            [id] => 2
            [name] => Joe
        )

    [2] => Array
        (
            [id] => 3
            [name] => Rick
        )

    [3] => Array
        (
            [id] => 4
            [name] => Mary
        )

    [4] => Array
        (
            [id] => 5
            [name] => Alice
        )

)

###Minimum And Maximum You can retrieve the minimum, maximum, and limit of results for the current page. This may be accomplished without even passign any data to the pagination class.

$page = new pagination(NULL,2,5);

echo $page->min; // 5
echo "\n";
echo $page->max; // 9
echo "\n";
echo $page->limit; // 5

###Next And Previous The next and previous methods return true or false depending on if there could be a next or previous page to your data.

$page = new pagination(15,3,5);

var_dump($page->next()); // bool(false)
var_dump($page->prev()); // bool(true)
echo $page->next_page(); // 4
echo $page->prev_page(); // 2
echo $page->total();     // 3