How to get an array of all controllers in a Codeigniter project ?
        Posted  
        
            by ashmckenzie
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ashmckenzie
        
        
        
        Published on 2010-05-09T11:32:57Z
        Indexed on 
            2010/05/09
            11:38 UTC
        
        
        Read the original article
        Hit count: 204
        
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';
© Stack Overflow or respective owner