Full CakePHP Application Part 12

CakeCatalog Main Index Page
OK so finally the full CakePHP application is coming to a close and this article is just going to wrap up a few loose ends. I've noticed a few errors and layout issues that I'm going to fix and hopefully by the end of the article the app will be fully complete.
Like all applications you could probably keep going forever adding new features, tweaking code and cleaning things up but there must come a time when you have to release it and the close the door. After this I probably wont be adding more features for some time but I do have a few ideas about great features you could try and implement.
The application can be found online at cakecatalog.jamesfairhurst.co.uk with a few more DVDs added.

Genre Filter Problem

When filtering DVDs by Genre there is a display error with only a few DVD covers being displayed per shelf. On further inspection the problem occurs because when the Genre filter is active I have to manually remove the DVDs that don't match. To display 8 DVDs per shelf I use the index of the array to determine the current position and because I've manually removed DVDs from the array the index has been messed up.
To fix this I've added a simple counter in the /app/views/dvds/index.ctp so instead of using the array key index I'm going to use the counter instead. The changed lines are below to you just need to do a quick copy and paste.
  1. // file: app/views/dvds/index.ctp  
  2.   
  3. <?php  
  4. // check $dvds variable exists and is not empty  
  5. if(isset($dvds) && !empty($dvds)) :  
  6.     // init dvd count  
  7.     $count = 1;  
  8. ?>  
  9. <div class="shelf">  
  10.       
  11.     <?php foreach($dvds as $key=>$dvd): ?>  
  12.         <?php  
  13.         // calculate if this dvd is the last on the shelf  
  14.         // if dvd number can be divided by 8 with no remainders  
  15.         $last_dvd = ( (($count) % 8 == 0)? 'dvd-last' : '' );  
  16.         ?>  

Image Upload Problem

When uploading images that already exist there are spaces in the new name that throws up some validation errors when viewing. This is a simple fix by removing the spaces from the new filename like so:
  1. // file: app/app_controller.php  
  2.   
  3. // from  
  4. $url = $rel_url.'/'.$now.' - '.$filename;  
  5. // to  
  6. $url = $rel_url.'/'.$now.'-'.$filename;  

Integrating the new Image Resize Class

Recently I created an Image Resize class that will resize images on the fly and save a cached version on disk so save processing time next time the image is requested.
I copied the images_controller.php file from that post and pasted it into the controllers directory. I also created a new cache folder located at /app/webroot/img/cache to hold all the processed images.
Below is a quick change to the index.ctp so utilise the Image Resize Class. I wont go through all the steps here to get up and running with is so check out my previous article if your interested.
  1. // file: app/views/dvds/index.ctp  
  2. <!--  
  3. <img src="/<?php echo $dvd['Dvd']['image']; ?>" alt="DVD Image: <?php echo $dvd['Dvd']['name'] ?>" width="100" height="150" />  
  4. -->  
  5. <img src="/images/view/100/150/true/<?php echo $dvd['Dvd']['image']; ?>" alt="DVD Image: <?php echo $dvd['Dvd']['name'] ?>" width="100" height="150" />  

Single DVD View

The view single DVD page is quite simple and will display the full details of the DVD along with the cover image. Not much has changed in the actual view.ctp file except that a new layout has been created and the page has been styled with CSS.

Single Genre View

The view single Genre page displays the DVD covers on the shelf like the main index page and includes a title to display what Genre is being displayed. The new layout has been used so that the header can be displayed without the form.

Source Code

The source code for this article can be downloaded using this link. If these articles are helping you out why not consider donating I can always use a beer! :)

Wrapping Up

Wow I've finally managed to wrap up most of the loose ends and the application is looking fairly complete, looking back I didn't think so time and effort would have gone into building an application like this but documenting every step is quite time consuming but hopefully its all been worth it.
Here a are few proposed improvements and features that I've not got round to implementing but they may get done in the future:
  • Template system to change the look of the front end from the admin panel
  • Amazon Lookup: When inputting a DVD automatically retreive data from Amazon
  • A sprinkle of Ajax to make everything run a little more smoothly
The final result can be seen at
http://cakecatalog.jamesfairhurst.co.uk/.

This entry was posted in . Bookmark the permalink.

Leave a Reply