Welcome Guest, Not a member yet? Register   Sign In
URI Routing and (optional) Function parameter
#1

[eluser]distractedBySquirrels[/eluser]
Hi there,

I have the following function inside the admin class:
Code:
public function users_view($filter = 'all', $by = 'username', $order = 'asc', $offset = 0)

I changed the URI from:
Code:
http://example.com/admin/users_view/role=inactive/username/asc/0/
to
Code:
http://example.com/admin/users/view/role=inactive/username/asc/0/

Since the last 4 segments are optional I set up 5 routes:
Code:
$route['admin/users/view'] = "admin/users_view";
$route['admin/users/view/(:any)'] = "admin/users_view/$1";
$route['admin/users/view/(:any)/(:any)'] = "admin/users_view/$1/$2";
$route['admin/users/view/(:any)/(:any)/(asc|desc)'] = "admin/users_view/$1/$2/$3";
$route['admin/users/view/(:any)/(:any)/(asc|desc)/(:num)'] = "admin/users_view/$1/$2/$3/$4";

Is there a way to reduce the routing? B/c I am going to have some more routing like that.




Theme © iAndrew 2016 - Forum software by © MyBB