slimphp / Slim-Documentation

Old Slim Framework 3 documentation
16 stars 13 forks source link

Injecting view #3

Closed harikt closed 9 years ago

harikt commented 9 years ago

Hi,

I think it is good to show how to inject a Twig view rather than calling $this['view'] inside controller / anonymous function.

$app->get('/hello/{name}', function ($request, $response, $args) {
    $this['view']->render('profile.html', [
        'name' => $args['name']
    ]);
})->setName('profile');

The idea is even if we are using a different framework, we can make use of the code without changes.