Welcome Guest, Not a member yet? Register   Sign In
Wildcards :num and :any not working in my routes
#8

[eluser]eggshape[/eluser]
If you write your regexp like this:

Code:
$route['item/:num'] = "item/index";
$route['example/:any'] = "example/lookup";

:num and :any will not be passed as parameters into your methods. First, :num and :any are CI's shorthand for [0-9] and (.+), which are regexp phrases that mean 'match digits' and 'match anything 1 or more'. :num and :any are replaced with their respective regexp phrases in the Route class. After replacement, CI does a preg_replace, **replacing** 'item/[0-9]' with 'item/index' in the uri string (as it is written).

So that is probably why you need to write it like this to pass as parameters:
Code:
$route['item/(:num)'] = "item/index/$1";
$route['example/(:any)'] = "example/lookup/$1";

Which is why bravoalpha's and dwdaniell's version works. When you use parentheses, you are capturing and saving everything in the parentheses. The $1 represents everything between the first set of parentheses. If you had 2 sets of (), the second one is saved as $2, and so on.

Think of it like you're inserting 'index' and 'lookup' between your original uri.

I don't think it matters where you define $route['default_controller'] and $route['scaffolding_trigger']. First $route is an associative array so there's really no order, and the default controller is used in case everything else fails.

Hope this helps.

Edit: I should add, that if the preg_replace doesn't work, then the original url is used. If that leads to nowhere you will get a 404.


Messages In This Thread
Wildcards :num and :any not working in my routes - by El Forum - 08-11-2007, 06:10 AM
Wildcards :num and :any not working in my routes - by El Forum - 08-11-2007, 11:02 AM
Wildcards :num and :any not working in my routes - by El Forum - 08-11-2007, 04:01 PM
Wildcards :num and :any not working in my routes - by El Forum - 08-25-2007, 11:41 AM
Wildcards :num and :any not working in my routes - by El Forum - 08-25-2007, 12:23 PM
Wildcards :num and :any not working in my routes - by El Forum - 08-25-2007, 12:50 PM
Wildcards :num and :any not working in my routes - by El Forum - 01-10-2008, 03:19 AM
Wildcards :num and :any not working in my routes - by El Forum - 01-10-2008, 07:22 PM
Wildcards :num and :any not working in my routes - by El Forum - 01-11-2008, 06:36 AM
Wildcards :num and :any not working in my routes - by El Forum - 01-11-2008, 11:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB