Professional CodeIgniter

(singke) #1

Chapter 4: Creating the Main Web Site


89


Displaying Product Categories


Now that you ’ ve figured out the home page view, the category view should go pretty fast. Remember
the discussion with Claudia? The category view is actually two views, and the original notes involved a
cat() controller function and a separate subcat() function.

There may be a better way to handle the differences between these two states. What ’ s involved in these
two states? The first is a category view that only displays subcategories, and the second is a subcategory
view that shows actual products.

To make all this work, you need to make a slight change involving the creation of a clothes category. The
clothes category will be the parent category of various other subcategories, namely, shoes, shirts, pants,
and dresses. Once the clothes category is created, set the parentid value for the shoes, shirts, pants, and
dresses category to match the ID of the new clothes category. While you ’ re at it, create a category named
fun , and place toys and games under it.

As soon as you ’ re done, open the MCats model in an editor and make a slight change to the
getCategoriesNav() function, limiting the query to retrieve only those categories that don ’ t have a
parentid value set. This will retrieve all top - level categories. While you ’ re at it, order the results
alphabetically by category name, and limit the list to active categories:

Figure 4 - 4
Free download pdf