Skip to content

Commit 33bc081

Browse files
committed
Update readme
1 parent 1a992c4 commit 33bc081

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,42 @@ composer require slim/php-view
2727
## Usage with Slim 4
2828

2929
```php
30+
use Slim\AppFactory;
3031
use Slim\Views\PhpRenderer;
3132

3233
include '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

0 commit comments

Comments
 (0)