Welcome Guest, Not a member yet? Register   Sign In
Problems with Routes
#1

[eluser]peterbz[/eluser]
I have 2 routes:

Code:
$route['used_cars/:any'] = "used_cars/show_listings/$1";
$route['used_cars/view'] = "used_cars/view";

However, CI doesn't seem to "see" the second one. So when the url is used_cars/view/1, it will use the first one. How do I make the first route so that it's "anything but 'view'"?
#2

[eluser]Mike Ryan[/eluser]
Hi,

Routes run in the same order they are specified - put the 'view' one first and it should do what you want.
#3

[eluser]peterbz[/eluser]
Is there a Regex that says something like "match any string but the exact words 'view'"
#4

[eluser]xwero[/eluser]
regexes are character oriented not word oriented. you can search for negative lookbehinds that is almost what you are after but it will not be sufficient for what you want to accomplish.

Like Mike wrote putting the route with view above the catch all route will work.
#5

[eluser]Colin Williams[/eluser]
You could do something like

Code:
$route['used_cars/([^view])'] = "used_cars/show_listings/$1";

but this rules out ALL paths with the arrangement "view" in it
#6

[eluser]Aken[/eluser]
You also need to add parentheses around ":any" if you want to load that part of the string into your function.

Code:
$route['used_cars/view'] = 'used_cars/view';
$route['used_cars/(:any)'] = "used_cars/show_listings/$1";




Theme © iAndrew 2016 - Forum software by © MyBB