Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2012 23:20
Show Gist options
  • Save anonymous/4263268 to your computer and use it in GitHub Desktop.
Save anonymous/4263268 to your computer and use it in GitHub Desktop.
Simple Slim Framework Controllers
<?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