Welcome Guest, Not a member yet? Register   Sign In
Route into a controller sub-directory
#11

[eluser]Derek Jones[/eluser]
You aren't capturing a pattern, sophistry, so there's nothing to replace. Try:

Code:
$route['([a-z]{3})'] = "welcome/index/$1";
#12

[eluser]sophistry[/eluser]
right! thanks for the tip! i added the parentheses and got a result - but not the expected result. ;-)

So, there is an inconsistency in the way that the controller method parameter and the uri->segment property are set. without parens, the segment property is set and the parameter sent to the controller is not. with parens both segment property and controller parameter are set.

the inconsistency should be addressed. code could be changed to make them both have the same data

OR

the docs might be amended to say "When using backreferences in a route there must be parentheses - the first parenthesis (capturing subpattern) defines $1, the second defines $2, etc..."

while adding that warning to the docs would make it so no one else has to report this "bug", i'd argue for changing the routing code to make the segment and the controller parameter agree whether or not there are parentheses. if there are no parentheses in the pattern the whole shebang should get put into $0. just like in preg_matchall(). in that PHP function the regex does not need the parens to capture a string - the whole pattern is expected to be in array index 0, the first parens defines array index 1 etc...

also, i've been doing some further testing and found that the :any and :num regexp shortcuts defined by CI and demonstrated in the docs also need parentheses to get their sub patterns to show up in the $1 - but they put the captured subpattern in *both $0 and $1* if you put parens.

these are the same:
Code:
$route['(:any)'] = 'welcome/index/$0';
$route['(:any)'] = 'welcome/index/$1';

hmmmn... :-)

EDIT: my response below was thoughtfully split into the feature request forums at http://ellislab.com/forums/viewthread/70410/
#13

[eluser]Derek Jones[/eluser]
That's because they are shortcuts, preventing you from writing the regex yourself. I don't think it's a good idea to make it capture the phrase by default, since it's perfectly reasonable to conclude that one doesn't want that to occur in a route. Oh, and make sure you aren't confusing $this->uri->segments with $this->uri->rsegments.




Theme © iAndrew 2016 - Forum software by © MyBB