move response logic to new view controller
This commit is contained in:
parent
59a8fc5164
commit
394b8d890c
2 changed files with 16 additions and 5 deletions
14
app/View/ViewController.php
Normal file
14
app/View/ViewController.php
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\View;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
use Slim\Views\Twig;
|
||||||
|
|
||||||
|
class ViewController
|
||||||
|
{
|
||||||
|
public function admin(Response $response, Twig $view): Response
|
||||||
|
{
|
||||||
|
return $view->render($response, 'admin.html.twig', []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use DI\Bridge\Slim\Bridge;
|
use DI\Bridge\Slim\Bridge;
|
||||||
use Slim\Views\Twig;
|
use Slim\Views\Twig;
|
||||||
use Slim\Views\TwigMiddleware;
|
use Slim\Views\TwigMiddleware;
|
||||||
|
use App\View\ViewController;
|
||||||
|
|
||||||
$container = require __DIR__.'/container.php';
|
$container = require __DIR__.'/container.php';
|
||||||
$app = Bridge::create($container);
|
$app = Bridge::create($container);
|
||||||
|
|
@ -14,10 +15,6 @@ $app->add(TwigMiddleware::create($app, $container->get(Twig::class)));
|
||||||
// change first param to false for production
|
// change first param to false for production
|
||||||
$app->addErrorMiddleware(true, true, true);
|
$app->addErrorMiddleware(true, true, true);
|
||||||
|
|
||||||
$app->get('/admin', function (Response $response, Twig $twig) {
|
$app->get('/admin', [ViewController::class, 'admin']);
|
||||||
return $twig->render($response, 'admin.html.twig', [
|
|
||||||
'name' => 'John',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue