Paging with Class

In Chapter 6, we created a web page to loop through a directory of images and display a thumbnail of each image. We're going to do the same thing here, but this time we'll incorporate the page navigator in order to display a limited number of images per page.

The very first thing you need to do is include the classes you'll be using. This is done with two require statements:

require 'PageNavigator.php';
require 'DirectoryItems.php';

The PERPAGE variable defines how many images to display on each page. Define it as a constant (5), because it is used in a number of different places on this page and you don't want to change its value accidentally:

//max per page
define("PERPAGE", 5);

Recall that within the PageNavigator

Get Object-Oriented PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.