CodeIgniter Forums
Deep level argumenting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Deep level argumenting (/showthread.php?tid=53849)



Deep level argumenting - El Forum - 08-11-2012

[eluser]RobertR[/eluser]
I think, this probably is novice question, but I am novice in CodeIgniter Smile

Well here is the problem, I'm trying to make categories and subcategories (dynamically generated) for store, and the main problem is that, I could manage to set different options to main category with _remap function in my controller. But, if I am trying to get deeper, then the same _remap function applies, and I am stuck there.

For example, the main category uri is http://project.com/store/fruits/, but for the subcategory, of course - http://project.com/store/fruits/apples.

I want to apply different view to 3rd segment, and still be able to control main category (fruits) with _remap function.

I want to use one controller over and over, but I think, it must be crazy to copy and paste the same function content for all subcategories (hundreds of them, disguised).

Maybe there is some way to do that, but I can't find out how... Help here! Smile

/Rob


Deep level argumenting - El Forum - 08-11-2012

[eluser]Lotus[/eluser]
remap has a second parameter $params which is an array of the other parameters passed in. So...
Code:
function _remap($main_category, $params = array())
{  
  // do stuff with main category...

  while ($subcategory =  array_pop($params))
  {
    // do stuff with each sub category
    // each iteration of loop is another level deeper of sub categories
  }
}



Deep level argumenting - El Forum - 08-11-2012

[eluser]RobertR[/eluser]
All right, and what should be those other parameters? Smile


Deep level argumenting - El Forum - 08-11-2012

[eluser]Aken[/eluser]
The parameters are pulled from your URI. http://ellislab.com/codeigniter/user-guide/general/controllers.html#passinguri


Deep level argumenting - El Forum - 08-12-2012

[eluser]RobertR[/eluser]
Okey, I think, I got the idea. I'll try Smile