PHP Classes

File: pagination_example.php

Recommend this page to a friend!
  Classes of Marcos Taranta   Holy Pagination   pagination_example.php   Download  
File: pagination_example.php
Role: Example script
Content type: text/plain
Description: Little usage example of the class
Class: Holy Pagination
Display pagination links using templates
Author: By
Last change: Added the use of range as an example from the version 0.2 of the class.
Date: 15 years ago
Size: 1,965 bytes
 

Contents

Class file image Download
<?php

include_once "pagination.php";

/**
 * Until now the constructor is always with no parameters, internaly the constructor only initiates some properties with
 * default values!
 */
$pagination = new Pagination();

/**
 * This method right here is a method to help building the pagination, you just suply the method with the total number
 * of ocurrencies that the pagination will have, and how much ocurrencies per page you want, so let's exemplificate, we are
 * making a photo pagination, so let's say whe scan the folder with php, and find 80 photos, and we want 7 photos per page,
 * so we do like this so the object will calculate how much pages the pagination will have, you can do manualy if you want
 * passing the number of pages to the method setPages(numberofpages).
 */
$pagination->generateNumberPages(80, 7);

/**
 * NEW: v0.2
 *
 * As of version 0.2 of the pagination class, I've added the range of the
 * pagination to be show, so let's say the current page is 5, and you set a
 * range of 3, the pagination will show the numbers of pages
 * "2 3 4 5 6 7 8", three more pages of the current page, and three less
 * pages of the current page.
 */
$pagination->setRange(3);

/**
 * Another thing that the object need to drawn the pagination, is the current page you're viewing, in this case, i'm geting
 * the current page by $_GET["page"] (since my $link property of the object is set by default like this "?page=%pageNumber%",
 * where the "%pageNumber%" is one of the tags that the object replaces with some value, in this case, the page number of the
 * link!
 */
if(empty($_GET["page"]) || intval($_GET["page"]) <= 0) {
   
$pagination->setCurrentPage(1);
}
else {
   
$pagination->setCurrentPage(intval($_GET["page"]));
}

/**
 * So finally we drawn our pagination on the screen, the final result will be something like "1 | 2 | 3 | 4 | ..." and so on!
 */
echo $pagination->getPagination();

?>