Quick _remap tutorial || code evaluation |
[eluser]meigwilym[/eluser]
Hi, I used a _remap function for the first time yesterday, and I thought I'd post what I did so others can learn. Saying that, I'm sure it's not perfect so any feedback is also welcome. I'm building a website for a TV production company. A section was needed to showcase their productions. These productions fall into categories: factual, drama, events, kids and co-productions. I wanted a url structure like this (to show one production): Code: example.com/productions/factual/the-production-name Code: example.com/productions/factual/ Code: example.com/productions/ I tried an approach using the index method, taking the category and production name as arguments, but this resulted in this url structure: Code: example.com/productions/index/factual/this-prod-name Code: function genre($category, $prodname = ''){ Code: # the segment of the url after the controller name is automatically passed as the argument This works great, giving me the desired url structure but with no code repetition. It's also straightforward to add extra categories. What does anyone else think? Regards, Mei
[eluser]xwero[/eluser]
The routing alternative : Code: $route['(productions)/(current|factual|kids|drama|events|co)'] = '$1/genre/$2'
[eluser]xwero[/eluser]
It works with the controller you have Code: class Productions extends Controller Code: $route['(productions)/(current|factual|kids|drama|events|co)(.*)'] = '$1/genre/$2$3';
[eluser]meigwilym[/eluser]
D'oh! Well, I'm glad I posted it. Thanks for your help. Mei
[eluser]xwero[/eluser]
I think _remap should be used when there is no routing solution possible, because the method is routing on controller level and so diffuses the routing to the controllers instead of keeping it in one single file.
[eluser]meigwilym[/eluser]
I'm using the URI Language Class, so these routes are already setup Code: $route['(\w{2})/(.*)'] = '$2'; Thanks, Mei
[eluser]xwero[/eluser]
just move it one segment ![]() Code: $route['(\w{2})/(productions)/(current|factual|kids|drama|events|co)(.*)'] = '$2/genre/$3$4';
[eluser]Boyz26[/eluser]
Code: $route['(\w{2})/(.*)'] = '$2'; Thanks! |
Welcome Guest, Not a member yet? Register Sign In |