tags:

views:

29

answers:

1

how do i load all class files in a folder in codeigniter?

its for when i develop, i create and delete class files very often, i don't want to add/remove everyone manually in autoload.php.

thanks!

+1  A: 

If you want to autoload a directory of libraries, in your application/config/autoload.php file, replace $autoload['libraries'] with this:

require BASEPATH."helpers/directory_helper".EXT;

$libraries = directory_map(APPPATH."libraries/", TRUE);

foreach($libraries as $library)
{
    if( ! is_array($library))
    {
        $class = str_replace(EXT, "", $library);

        $autoload['libraries'][] = strtolower($class);
    }
}

I haven't tested that, but it I'm guessing that will work. You could write your own helper file with your own function and just require it instead of CI's directory_helper. That way you could load libraries, helpers, configs, models, etc. You could configure it to load sub directories, too... if you wanted.

bschaeffer