Welcome Guest, Not a member yet? Register   Sign In
Remap or routing? Can either do this example dynamically?
#1

[eluser]err403_love[/eluser]
I'd have for instance:

Code:
/ // main index, default controller "main"
/content/news/
/content/reviews/
/content/interviews/
/content/__________/  // (wildcard... These forums wouldn't allow use of an asterisk.)
/gallery/
/about/
/contact/
... // and so on,  with the non-"/content/" URIs

But I'm trying to allow for some flexibility when it comes to naming content-type/categories, and the stickler is that I don't actually want "/content/" to remain in the URI whatsoever.

Meaning one deployment of this CMS may have entirely different content categories, so I can't hardcode anything into routes.php, I don't think. And the secondary problem is getting a request for "/gallery/" to not be mistaken for a request for "/content/gallery/"...

I thought one solution could be (pseudocode): "if NOT "/" and NOT "/gallery/" et al, then route to the "content" controller"

But this breaks for new non-"content" modules, without updating the routes every single time.

So I was thinking if there is any way to do something like so (pseudocode):

Code:
// Example URI = /blog
// First jump to "content.php" controller...
// Query DB for list of categories, check for "blog"

if "blog" in $array_of_categories               // **it is**
    jump to function index($category)           // (it will)
else
    redirect to controller named "blog.php"     // (it won't)

#########################

// Example URI = /gallery
// first jump to "content.php" controller...
// Query DB for list of categories, check for "gallery"

if "gallery" in $array_of_categories            // **it is NOT**
    jump to function index($category)           // (it won't)
else
    redirect to controller named "gallery.php"  // (it will)

So a few questions arise:

1. You can't load controllers from other controllers in stock CI, correct? I'm using HMVC, though, I thought maybe there is a way with that.
2. Is there any actual way to "redirect" to a different controller?
3. Is this idea stupid and/or computationally expensive for the server?
4. Tie-in to #3.. This would then necessitate 1 global query for every page load.. Does CI's page caching work by URI-only, and therefore bypass this global query except when the page is re-cached? Because then "computationally expensive" wouldn't even happen.

... And of course if there is some more obvious way I would like to know. Smile

I imagine I may just have to do something inside of MY_Router? I already use it for HMVC, so I guess this would also be a pain to update every time with my changes..


P.S. - I also thought about doing this all inside the "main" controller, and scrapping a separate "content" controller, but I'm not really sure that'd make it any easier? I wanted to keep the main page code as separate as possible from the weblog/categories code anyway..

I also thought, can you query the DB inside of "routes.php" to generate the routing code necessary? For example grab an array of the categories from the DB, and generate the routing code, e.g. "(blogs|reviews|interviews|)

I also thought, could I simply have CI be able to edit routes.php or is this too dangerous, security-wise?




Theme © iAndrew 2016 - Forum software by © MyBB