• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URL Routing Issue

#1
[eluser]Unknown[/eluser]
I'm pulling my hair out over this one. I've used CI for a couple projects now and I honestly don't understand why this isn't working. My understanding is that routes work top-down, so if the first one matches it stops there.

If I have this URL,
domain.com/first-person-inside-the-smart-car/1738722217

it always goes to the first route defined below. I can't get it to go to the second route. Has anyone bumped into this issue before? It's driving me crazy and I can't figure out why it doesn't work like I've always known it to.

Code:
$route[':any/:any/(:num)'] = 'video/setPlaylist/$1';
$route[':any/(:num)'] = 'video/setPlaylist/null/$1';

#2
[eluser]swanky[/eluser]
Switch them around. Numbers are anything.
Code:
$route[':any/(:num)'] = 'video/setPlaylist/null/$1';
$route[':any/:any/(:num)'] = 'video/setPlaylist/$1';

#3
[eluser]Unknown[/eluser]
[quote author="swanky" date="1220991046"]Switch them around. Numbers are anything.
[/quote]

When I switch them around, a url like domain.com/playlist-name/video-1/12345678 gets routed to this one:

Code:
$route[':any/(:num)'] = 'video/setPlaylist/null/$1';

which makes absolutely no sense to me. The second portion of the URL isn't even a number, but the number on the end (in this example 12345678) is getting passed into the controller.

#4
[eluser]swanky[/eluser]
It's the number in video-1 (i.e. 1) that's causing your problems. I'd use a regex instead if your second segment will be a alpha numeric.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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