Skip to content

Instantly share code, notes, and snippets.

@tobsn
Created December 17, 2010 01:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobsn/744330 to your computer and use it in GitHub Desktop.
Save tobsn/744330 to your computer and use it in GitHub Desktop.
controller loader for slim framework
<?php
Slim::hook('slim.before.dispatch', function () {
list( $type, $controller_name, $controller_action ) = array_merge( explode( '.', Slim::router()->current()->getName() ), array( null,null,null ) );
if( $type == 'controller' ) {
$file = './controllers/'.$controller_name.'.controller.class.php';
if( !is_readable( $file ) ) { return false; }
require_once( './controllers/base.controller.class.php' );
require_once( $file );
$class = $controller_name.'Controller';
$controller = new $class( Slim::getInstance() );
$params = Slim::router()->current()->getParams();
$action = ( isset( $params['action'] ) && is_callable( array( $controller, $params['action'] ) ) ) ? $params['action'] : 'index';
$controller->$action();
}
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment