Welcome Guest, Not a member yet? Register   Sign In
Dynamic URLs
#1

[eluser]Unknown[/eluser]
Hi,

I googled my ass off but couldn't find quite the thing I'm looking for, so this is basically a last resort :-)

Just to be clear, I'm not looking for a 'default controller for everything' solution (at least I think I'm not).

I would like my application to be fully capable of handling totally dynamic URLs (domain.tld/something-something-here). The URL would be set in the database with the 'system path'.

Basically something like this:

slug | system_path
something-something-here | controller/function/params

So when 'something-something-here' request came in, CodeIgniter would actually fire up the appropriate controller and functions with params.

I know I have to rewrite the Router, but have no idea how. The thing is, I'd like CI to actually run the right controller instead of redirecting (I guess the 'default controller' solution could be used if I wanted redirects).


OpenCart has just the thing I'm looking for, example:
totally-awesome-product.html | index.php?route=product/product&product_id=43


This would run the product controller, product function and pass in the product_id of 43 as param.

Any ideas?

I hope my question's clear enough, if not, just let me know.

Thanks!
#2

[eluser]Clooner[/eluser]
I suggest you look into reading the user guide http://ellislab.com/codeigniter/user-gui...uting.html

This will explain in detail the workings of the routing function and handles exactly as you are describing, the first argument is the controller and the second argument (if given or it will assume index) is the method.
#3

[eluser]Unknown[/eluser]
Thanks for your input, Jeroen Schaftenaar.

I've looked at similar solutions - constantly rewriting my routes.php config file with fresh/updated SEO URL's on each entry insert/update (adding routes manually is out of the question), but it's not quite what I'm looking for.

Let me try to rephrase my question - is there any way to tell the CI Router which controller/function to load based on some db query results?

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB