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 that will give me what I'm after ?
Here is the code snippet from the routes.php file where I would like to access the array: -
// I'd like $controllers to be dynamically populated by a method
//
$controllers = array('pages', 'users');
// Loop through each controller and add controller/action routes
//
foreach ($controllers as $controller) {
$route[$controller] = $controller . '/index';
$route[$controller . '/(.+)'] = $controller . '/$1';
}
// Any URL that doesn't have a / in it should be tried as an action against
// the pages controller
//
$route['([^\/]+)$'] = 'pages/$1';
UPDATE #1
To explain a little more what I'm trying to achieve.. I have a Pages controller which contains pages such as about, contact-us, privacy etc. These pages should all be accessible via /about, /contact-us and /privacy. So basically, any action/method in the Pages controller should be accessible without having to specify /pages/<action>.
Not sure if I'm going about this the right way ?