CodeIgniter Forums

Full Version: Looking for a dynamic routing solution
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I'm developing an app that allows users to create custom pages that are then public on the web for people to visit (similar almost to a CMS). I am trying to find a way to make these pages available via a simple URL like:


Where "page_address" is specified by the user after the page is created and published. So I've got a database table full of pages along with their addresses... problem is, using the format above, CI is expecting page_address to be a controller and it's not. I'm looking for a way to check my database for that address and if it exists set the controller/method appropriately. I would jump at a regular expression solution, but the page_address could be anything so it really needs to be checked against the DB.

I've tried extending the native CI Router, but can't gain access to the DB to do a query. I also found this post:

But sincerely hope there is a simpler/better way to accomplish this.

Any ideas?

El Forum

Why not just add a route for:

$route["(:any)"] = "routing_controller/routing_function";

Then use the URI library or regex or whatever you want to route in that function?

Just reread your post and I guess I didn't really answer your question since that wouldn't really be routing, you'd have to expose controller/function names. I can't see a simpler way to do what you're asking (cleanly) than the link you posted.

El Forum

noctrum, I actually tried your recommendation first.

$route[":any"] = "controller/method";

I thought it would work because all "page_address" requests will be handled by the same controller. Problem is none of the default program routs worked anymore. All requests were processed by that one route and thereby killing the rest of the app.

Yeah, I'm starting to think the method linked in my first post is my best bet.