• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
routing depth

I am working on an application that has a lot of location based data that needs to be organized. I created a location controller to be the jumping off point to drill down to this data. So a user can go to http://xyz.com/location and choose a state. That generates a new page at a url like http://xyz.com/location/Missouri where they can chose a city from the state Missouri. Then they would drill down to other categories based on the location(example: http://xyz.com/location/Missouri/Springfield/cars/bmw). This is where I realized routing doesn't scale they way I had thought.

$route['location/(:any)'] = "location/state/";
$route['location/(:any)/(:any)'] = "location/city";

(:any)/(:any) obviously doesn't work.
Is there a way to maintain the uri flow and continue to drill down into the granular data?

Ahh but this does work the way I expected it to. The most granular route must be at the top and filter its way down.
$route['location/(:any)/(:any)'] = "location/city";
$route['location/(:any)'] = "location/state/";

Yep, go from the most segments to the least, because as soon as it finds a match it will quit looking, and (:any) will match, well, everything (including segments).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.