Professional CodeIgniter

(singke) #1

Chapter 4: Creating the Main Web Site


81


The reason for these two errors is simple. You haven ’ t established a $data[ ’ main ’ ] variable in your
controller, and the view is expecting some kind of value so it can load an appropriate subview in that
space. Why is it called $data[ ’ main ’ ]? It ’ s called that because it will contain the “ main ” content for any
given page, be it a Contact Us form, a home page listing, or a product page. Using a dynamic variable
like this allows you to reuse templates.

The rest of this chapter focuses on how to create the content for this important variable. To do that, you
will need to refer to the initial sketches created with Claudia. Starting with the next section of this
chapter, you ’ re going to be doing just that, working through each page of the application.

By the end of the chapter, you should know most of what you need to know to create an MVC web site.
The last part, building the actual Shopping Cart application, is left for Chapter 5 , only because the level
of detail involved requires further attention.

Displaying the Home Page


So now you know what you have to do — populate the main variable in the template view. Before doing
this, it ’ s a good idea to look at the mockup you worked on with Claudia. As a reminder, it ’ s shown in
Figure 4 - 3.

Figure 4 - 3

What Claudia wants on the home page is a main featured product with three other featured products to
the right, each from a different category. The main featured product includes a large image and a short
description, while the three others consist of a small thumbnail image and a title (no description). Both
groups have appropriate links that allow the visitor to buy now or see more detail.

At the moment, you could spend a lot of time on display or look and feel issues, but you ’ re going to take
the MVC approach and work on the model first. Why? Because you need to have some data to work
with first, and the model is where you do that.
Free download pdf