4.1. 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. 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.
Open the MProducts model (/system/application/models/mproducts.php). This model contains two bare-bones functions: getProduct() and getAllProducts(). At first glance, the getProduct() function looks promising, as you could call it four times and then check in each case for a featured designation of TRUE (or category IDs), but this approach feels too heavy-handed. In other words, it's like using a bulldozer where a shovel (or even a spoon) would suffice. It would be better for all involved ...
Get Professional CodeIgniter® 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.