Open Mark-H opened 9 years ago
It also looks like
$app->get('/hello/{name}', function ($request, $response, $args) {
$this['view']->render('profile.html', [
'name' => $args['name']
]);
})->setName('profile');
should be something along the lines of this:
$app->get('/hello/{name}', function ($request, $response, $args) {
$this->view->render($response, 'profile.html', [
'name' => $args['name']
]);
})->setName('profile');
.. unless I'm being a total noob here, which is totally possible as this is the second time I'm playing with Slim, and the first time was 2.6 too :P
Yeah, if we call:
$this['view']
This return:
Fatal error: Cannot use object of type Slim\App as array
Also add that Twig View extension have 2 methods (fetch and render):
$app->get('/', function($request, $response) {
$output = $this->view->fetch('index.html', ['name' => 'John']);
return $response->write($output);
});
$app->get('/', function($request, $response) {
$this->view->render($response, 'index.html', ['name' => 'John']);
return $response;
});
It would be desirable get an explanation of their differences
jups, array notation is from Pimple, which is the container being used by Slim. Object property notation is from the Slim\App object, which ports to the container.
This is a recent change so could be that the documentation is not up to date yet. Should be solved when Slim 3.0 becomes final.
According to http://docs-new.slimframework.com/features/templates/ ("Register the view service"), the code to use is:
However that throws a fatal error
Call to undefined method Slim\App::register()
.From the readme at https://github.com/slimphp/Twig-View it seems the correct code is actually:
.. which seems to at least get rid of the error.