0
votes

I've upgraded from Codeigniter version 2.x to 3.x and noticed that the URI routing behaves differently when passing in multiple segments.

In version 2.x, I was able to pass the following URL variations:

domain.com/function/arg1
domain.com/function/arg1/arg2
domain.com/function/arg1/arg2/arg3

Where $route['function/(:any)'] = 'function/$1' would work for all three URL variations given that my function call is function($arg1, $arg2 = 0, $arg3 = 0) which allows arg2 and arg3 to be optional and be passed in as $1 in the routing rules.

In order for it to work in version 3.x, I find that I have to set up my routing as:

$route['function/(:any)'] = 'function/$1';
$route['function/(:any)/(:any)'] = 'function/$1/$2';
$route['function/(:any)/(:any)/(:any)'] = 'function/$1/$2/$3';

Is there any way I can simplify the routing so that it will pass all remaining segments without having to create separate routing rules for each variation of the number of possible segments?

1
I think CodeIgniter 3 is strict about the number of parameters so I don't know if there's a simple way for you to use fewer routes. - pacificpelican
Did you read the v3.0 upgrade notes? - Sparky

1 Answers

2
votes

(:any) is not supposed to match the / character and this bug was fixed in version 3.

You should thoroughly read the v3.0 upgrade guide...

Quoting "Routes containing :any" -

There are certainly many developers that have utilized this bug as an actual feature. If you’re one of them and want to match a forward slash, please use the .+ regular expression:

(.+)    // matches ANYTHING
(:any)  // matches any character, except for '/'