Class 7 – Assignment #1
Posted: October 31st, 2009 | Author: amos | Filed under: assignments, php | Tags: arrays, class 7, templates | No Comments »Your in-class assignment today is to update your e-commerce pages from the previous class to be more “dynamic” and “templatized”.
Templatize the common sections of all pages in the entire site
Use separate PHP include files for the top ad banner, global navigation, breadcrumbs, skyscraper ad, and footer. On a real site, these sections would be the more-or-less the same on all pages, so you would want to have them stored in reusable files. These files will be included into the main XHTML file for each page using the include() function of PHP. Feel free to check out the include examples that are up on the server.
- _header.php
- _breadcrumbs.php
- _ad_banner.php
- _ad_skyscraper.php
- _footer.php
Templatize the products
Once you have finished that, it’s time to start templatizing the actual products that are displayed on the page as well. This would, in theory, allow you to use the same page template for multiple categories of products.
We will do this in a different way than how we templatized the repeating sections of the page. We will be using multidimensional arrays this time. This exercise will be useful as a preparation for when we start to store data in databases.
Eventually, we will want the data for the products to be pulled from a database. But for now, we’re just going to store data in an array as an intermediary step to that goal.
To templatize the products, create a PHP multidimensional array that contains all of your product data. And use a PHP foreach loop to loop through that array and display the product data for each product on your page, rather than having it all hard-coded in the XHTML.
Do the tutorials, understand the examples
You are going to have to go through all the PHP tutorials on the Tizag site and my introduction to arrays in order to get a grasp of arrays and multidimensional arrays in particular.
Here is an example of how to get starting using a multidimensional array for this assignment. I did not show how to use the foreach loop here, so you will have to investigate that, based on the example of looping through an array using the foreach command shown here.
Be sure to keep a backup of the work you did on the e-commerce page in previous classes – do not overwrite it, just make a copy of it.
Links to helpful documentation
- Tizag PHP tutorials (read through all these)
- Tizag’s array tutorial (particularly important for this assignment)
- My introduction to arrays (you need to know this)
- Another multidimensional array tutorial
- Example of using a multidimensional array
No related posts.
Leave a Reply