• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple subcategory levels - need routing/controller suggestions please!!


I'm working on a very basic product display site for a client.

Some of the products drill down to a 3rd level subcategory, so basically:

+ Main Product Categories
++ Sub Product Categories
+++ Product Series for each Product Sub Category (basically a 3rd level of sub cats)

So I need to get to that 3rd level of categories, then next comes a high-level summary page of products for that 3rd level of subcategories (which would be another URI segment) and then the product display page for a chosen product.

The whole URL ends up looking like: http://localhost/category/subcategory/subcategoryseries/seriesproductsummary/productdisplaybyID/

I realize this isn't anything out of the ordinary at all. It's just that I can't seem to figure out how to correctly accomplish this.

It seems in my particular situation I have to create sub-directories in my main controllers directory and additional sub-directories in there and then do some custom routing in routes.php. Too much required custom routing seems anything BUT dynamic to me -- but I'm sure I'm just completely missing something that's already built in. I'm new with CodeIgniter so I wanted to find out what the best approach would be for what I'm trying to accomplish.

Any suggestions are greatly appreciated!! If I left out any useful information you might still need, just let me know.

Thanks again in advance!
- T

Why not try this:

Controller named "category" and a function named "view" (or similiar) that takes the category, the subcategory, the subcategoryseries, the seriesproductsummary and the productdisplayid as parameters.

or am i totaly not getting what you want to do?

[eluser]Tom Schlick[/eluser]
why not store each category, sub, sub sub.... in a table that stores the name and the parent ID

then in the controller call


Thanks for the replies, guys!

I think you're on the right track as to what I'm hoping to achieve, but am just basically not sure how to set it up in my controller. Can you expound a bit with a simple example of a controller that I can use as a visual? It would help greatly. I know how to set up controllers in general...it's just this particular scenario of how to setup a function that will take additional parameters to drill down into deeper category levels without me having to set up additional controller pages (which I know is not the ideal solution).

trs21219 - Actually I already have tables set up as you suggested. I have each separate level of categories in their own tables (categoriesLevel1, categoriesLevel2, categoriesLevel3) and then association tables for all sub categories that are associated with other top or sub levels.

Hope this clarification helps. Let me know if you need any additional info from me.

Thank you again for your assistance! I appreciate it!


The only catch with doing it this way is that you require a database call for each sub category level. Perhaps this method will help you: http://www.alandelevie.com/2008/07/12/re...-database/

Or have a look at nested sets. There are a couple of libraries for CI, e.g. MPTtree.

Thanks, guys! I'll take a look at these.

I appreciate it!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.