Welcome Guest, Not a member yet? Register   Sign In
MY_Controller process a common URI segment
#1

[eluser]Unknown[/eluser]
I'm looking for suggestions on how to go about processing a common URI segment that all of my controller functions will need.

Basically, I have a single site with multiple ways to view data. Depending upon which way you drill down into the site, a subset of the data will be available to you and your theme (color/skinning) needs to stay consistent. It will be easier to explain with some fake data.

Label 1 is a parent of Label 2, so Artist A is accessible via Label 1 and Label 2. If you drill down to Artist A by by going through Label 1, the site will be greenish. If you drill down to Artist A by going through Label 2, the site will be orangeish. That's an over simplification, but it gets at the heart of what I'm trying to do.

So my URLs might look like (even though I'm ultimately getting the same artist)...

www.site.com/label1/artist/get/<id>;
www.site.com/label2/artist/get/<id>;

Generally, www.site.com/{context}/{controller}/{function}/{arguments...}

As a first pass at this, I defined routes that basically take the context and pass it in as the last argument to every function.

$route['(:any)/artist/(:num)'] = 'artist/get/$2/$1';

Clearly that's not very elegant. My gut reaction is to create a custom controller class MY_Controller and somehow make the "context" available in that class, so that any of my controllers can simply do $this->get_context(), and I don't have to muddy up each function's argument list by passing in the context.

I'm sketching out potential ways to do this, but I thought that I would check with the community and see what suggestions you have. I am new to CI but am definitely enjoying it. Thanks for the help!




Theme © iAndrew 2016 - Forum software by © MyBB