Created
July 30, 2015 21:22
-
-
Save silentworks/39ef154297145536be49 to your computer and use it in GitHub Desktop.
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 | |
$app->get('/', function ($request, $response, $args) | |
{ | |
$container = $this->getContainer(); | |
(new TestController($container['user'], $container['view']))->all($request, $response, $args); | |
}); | |
$app->get('/:id', function ($request, $response, $args) | |
{ | |
$container = $this->getContainer(); | |
(new TestController($container['user'], $container['view']))->show($request, $response, $args); | |
}); |
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 | |
$container = $app->getContainer(); | |
$container['TestController'] = function ($container) | |
{ | |
return new TestController($container['user'], $container['view']); | |
}; | |
$app->get('/', 'TestController:all'); | |
$app->get('/:id', 'TestController:show'); |
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 TestController | |
{ | |
public function __construct(\Spot\MapperInterface $user, $view) | |
{ | |
$this->user = $user; | |
$this->view = $view; | |
} | |
public function all($request, $response, $args) | |
{ | |
$users = $this->user->all(); | |
$this->view->render('users.twig', compact('users')); | |
} | |
public function show($request, $response, $args) | |
{ | |
$user = $this->user->get($args['id']); | |
$this->view->render('user.twig', compact('user')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment