O'Reilly logo

Professional CodeIgniter® by Thomas Myer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.2. 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:

function getCategoriesNav(){ $data = array(); $this->db->where('parentid <', 1); $this->db->where(status', 'active'); $this->db->orderby('name','asc'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required