Welcome Guest, Not a member yet? Register   Sign In
simpler way to handle multiple segments in URI routing for Codeigniter 3.x
#1

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?
Reply
#2

See https://www.codeigniter.com/userguide3/i...aining-any
Reply




Theme © iAndrew 2016 - Forum software by © MyBB