How do I route "mysite.com/clean-article-title" to the correct controller ? |
[eluser]little brittle[/eluser]
I'm having trouble figuring out how to set up CI so that "mysite.com/clean-article-title" routes to "mysite.com/blog/article/clean-article-title". I was directed to an article here: http://remysharp.com/2008/03/25/codeigniter/ But I can't figure out how to get this working. Could anyone explain the easiest way to get this working?
[eluser]Bramme[/eluser]
[quote author="little brittle" date="1212193742"]I'm having trouble figuring out how to set up CI so that "mysite.com/clean-article-title" routes to "mysite.com/blog/article/clean-article-title". I was directed to an article here: http://remysharp.com/2008/03/25/codeigniter/ But I can't figure out how to get this working. Could anyone explain the easiest way to get this working?[/quote] Try this $routes['([a-z0-9-]+)'] = "blog/article/$1"; NOTE: you can't use CAPITAL letters in your clean article title. If you want to, use [a-zA-Z0-9-]as regex.
[eluser]little brittle[/eluser]
Well, that would work. But wouldn't you have to specify all of your controllers in the 'routes' file before that line? Right now it doesn't check for a controller match and thinks everything is a blog article.
[eluser]Bramme[/eluser]
[quote author="little brittle" date="1212204522"]Well, that would work. But wouldn't you have to specify all of your controllers in the 'routes' file before that line? Right now it doesn't check for a controller match and thinks everything is a blog article.[/quote] True, everything will be a blog entry... I don't really know how els you could do it... You could try smth like mysite.com/blog-clean-title/ and then use regex to cut off the blog, incicating it's a blog entry... Sudden idea: you can use multiple routes. For instance, you could use: $route['([a-z0-9-]+)'] = "blog/blahblah/$1"; $route['controller/(:any)'] = "controller/$1"; etc... |
Welcome Guest, Not a member yet? Register Sign In |