codeigniter how do i setup routing for controller class and method?
You don't need further modifications. In fact, even this line is redundant:
$route['report/(:any)'] = 'report/$1';
This one is also redundant:
$route['/'] = 'home/index';
since the default controller is set to 'home' and the default method is always index
.
Look at how CI works with URLs: https://www.codeigniter.com/user_guide/general/urls.html
So, /localhost/report/generate
would look for the Report
controller, and load its generate
method. That's how it works out-of-the-box, no routing needed.
And this route is fine:
$route['recent/(:num)'] = 'home/recent/$1';
If will take the URL /localhost/recent/123
and will load the Home
, controller, recent
method and will pass 123
as the first method parameter.