tailieunhanh - OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P9

OBJECT-ORIENTED PHP Concepts, Techniques, and Code- P9:A number of years ago, before I started using PHP, I created dynamic web pages using C. This really wasn’t too different from some of the other options available at the time, though it seems almost unthinkable now. Creating a dynamic page meant outputting HTML from your script and recompiling that script if any changes needed to be made. | else then calculate offset totaloffset offset PERPAGE If no query string is passed into the page you want to begin displaying images at the beginning of your list so you set O totaloffset to 0. If offset does have a value multiplying it by @ the PERPAGE value calculates the start position within the array of image filenames. The name of the directory you want to use is assigned to the variable directory directory graphics di new DirectoryItems directory Listing 8-1 Hard-coded directory name Because you want to display the directory of images in the graphics directory pass the value graphics to the constructor of the Directoryitems class. The imagesOnly method filters out all non-images and the method naturalCaselnsensitiveOrder ignores case and orders numerically where appropriate. di- imagesOnly di- naturalCaseInsensitiveOrder In Chapter 6 when you displayed all the thumbnails on one page you retrieved the entire list of filenames from the Directoryitems class instance. Since the page navigator controls the starting position and since you can retrieve a slice of the array you need only retrieve a specific number of items here. Do this by passing the getArraySlice method a start position and the number of items you wish to display. get portion of array filearray di- getFileArraySlice totaloffset PERPAGE Displaying an Array Slice You retrieve each filename and pass it to the file so it can serve as the file source for an img tag. You don t need to make any changes to the version of the file you used in Chapter 6 it includes the Thumbnailimage class and uses it to create a reduced image. The code to loop through the thumbnail images hasn t changed from Chapter 6 either. For ease of reference it s reproduced in Listing 8-2. Using the PegeNevigetor Gloss 61 echo div style text-align center echo Click the file name to view full-sized version. br path specify size of thumbnail size 100 foreach O filearray as key value path directory . key .

TỪ KHÓA LIÊN QUAN