Skip to content

Instantly share code, notes, and snippets.

@silentworks
Created July 30, 2015 21:22
Show Gist options
  • Save silentworks/39ef154297145536be49 to your computer and use it in GitHub Desktop.
Save silentworks/39ef154297145536be49 to your computer and use it in GitHub Desktop.
<?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);
});
<?php
$container = $app->getContainer();
$container['TestController'] = function ($container)
{
return new TestController($container['user'], $container['view']);
};
$app->get('/', 'TestController:all');
$app->get('/:id', 'TestController:show');
<?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