File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,22 +27,42 @@ composer require slim/php-view
2727## Usage with Slim 4
2828
2929``` php
30+ use Slim\AppFactory;
3031use Slim\Views\PhpRenderer;
3132
3233include 'vendor/autoload.php';
3334
34- $app = Slim\ AppFactory::create();
35+ $app = AppFactory::create();
3536
36- $app->get('/hello/{name}', function ($request, $response, $args ) {
37+ $app->get('/hello/{name}', function ($request, $response) {
3738 $renderer = new PhpRenderer('path/to/templates');
3839
39- return $renderer->render($response, 'hello.php', $args );
40+ return $renderer->render($response, 'hello.php');
4041});
4142
4243$app->run();
4344```
4445
45- Note that you could place the PhpRenderer instantiation within your DI Container.
46+ ## DI Container Setup
47+
48+ You can place the ` PhpRenderer ` instantiation within your DI Container.
49+
50+ ``` php
51+ <?php
52+
53+ use Psr\Container\ContainerInterface;
54+ use Slim\Views\PhpRenderer;
55+ // ...
56+
57+ return [
58+ PhpRenderer::class => function (ContainerInterface $container) {
59+ $renderer = new PhpRenderer('path/to/templates');
60+
61+ return $renderer;
62+ },
63+ ];
64+
65+ ```
4666
4767## Usage with any PSR-7 Project
4868
You can’t perform that action at this time.
0 commit comments