How to route 2 parameters to a controller?

eric.itzhak picture eric.itzhak · Nov 6, 2012 · Viewed 51.6k times · Source

This seems really basic but i can't get the hang of it.

I'm trying to send more then one parameter to a method in the controller, like this :

http://localhost/ci/index.php/subjects/3/state

This is the routings i've tried :

$route['subjects/(:num)'] = 'subjects/view/$1';
$route['subjects/(:num)/{:any}'] = 'subjects/view/$1/$2';

the method accepted 2 paremeters :

public function view($slug, $id = null){

}

but i seem to get a 404. How can i get this to work? i need the view method to always accept 1 parameter and optional other parameters.

NOTE : I am including the url helper.

Answer

umefarooq picture umefarooq · Nov 6, 2012

you have problem with your route brackets just change it from {} to () brackets will work

from

$route['subjects/(:num)/{:any}'] = 'subjects/view/$1/$2';

to

$route['subjects/(:num)/(:any)'] = 'subjects/view/$1/$2';