Created
December 11, 2012 23:20
-
-
Save anonymous/4263268 to your computer and use it in GitHub Desktop.
Simple Slim Framework Controllers
This file contains hidden or 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 | |
class App extends \Slim\Slim | |
{ | |
public function mount($pattern, $method) | |
{ | |
list($controller, $action) = explode('::', $method); | |
$app = $this; | |
return $this->map($pattern, function() use ($app, $controller, $action) { | |
$controller = new $controller($app); | |
call_user_func_array(array($controller, $action), func_get_args()); | |
}); | |
} | |
} | |
class HomeController | |
{ | |
protected $app; | |
public function __construct($app) | |
{ | |
$this->app = $app; | |
} | |
} | |
$app = new App; | |
$app->mount('/', 'HomeController::indexAction')->via('GET')->name('home'); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment