Created
December 17, 2010 01:25
-
-
Save tobsn/744330 to your computer and use it in GitHub Desktop.
controller loader for slim framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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