codeguy/Slim — Issue #217: controllers auto load
Author: blendsoft
Created: 2012-01-08 15:37:56+00:00
State: open

hello

I want to use external controllers files, which will be autoloaded
so i made
controllers dir in main dir
and MainController.php in it:

get('/', function(){
//require_once('controllers/MainController.php');..
$controller = new controllers\MainController();
$controller->index();
});

but i want controller will be autoloaded
but autload methods autoload only files with "Slim"

so I changed :

public static function autoload( $class ) {

if ( strpos($class, 'Slim') !== 0 ) {
$class = str_replace('\\', '/', $class) . '.php';..
require_once($class);.
}

$file = dirname(__FILE__) . '/' . str_replace('_', DIRECTORY_SEPARATOR, substr($class,5)) . '.php';
if ( file_exists($file) ) {
require $file;
}
}

now controllers are autoloaded
It would nice feature if not only Slim classes can by autoloaded