I\'d like to obtain a list of all controllers in a Codeiginiter project so I can easily loop through each of them and add defined routes. I can\'t seem to find a method tha
Well to directly answer to coding question, you can do this:
foreach(glob(APPPATH . 'controllers/*' . EXT) as $controller)
{
$controller = basename($controller, EXT);
$route[$controller] = $controller . '/index';
$route[$controller . '/(.+)'] = $controller . '/$1';
}
Buuuuuut this may not work out to be the most flexible method further down the line.
There are a few other ways to do it. One is to create a MY_Router and insert
$this->set_class('pages');
$this->set_method($segments[0]);
before/instead of show_404();
That will send /contact to /pages/contact, but only if no controllers, methods, routes are mapped to first.
OOOOOOORRRRRR use Modular Separation and add the following to your main routes.php
$routes['404'] = 'pages';