Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Jul 13, 2024
1 parent 1a992c4 commit 33bc081
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,42 @@ composer require slim/php-view
## Usage with Slim 4

```php
use Slim\AppFactory;
use Slim\Views\PhpRenderer;

include 'vendor/autoload.php';

$app = Slim\AppFactory::create();
$app = AppFactory::create();

$app->get('/hello/{name}', function ($request, $response, $args) {
$app->get('/hello/{name}', function ($request, $response) {
$renderer = new PhpRenderer('path/to/templates');

return $renderer->render($response, 'hello.php', $args);
return $renderer->render($response, 'hello.php');
});

$app->run();
```

Note that you could place the PhpRenderer instantiation within your DI Container.
## DI Container Setup

You can place the `PhpRenderer` instantiation within your DI Container.

```php
<?php

use Psr\Container\ContainerInterface;
use Slim\Views\PhpRenderer;
// ...

return [
PhpRenderer::class => function (ContainerInterface $container) {
$renderer = new PhpRenderer('path/to/templates');

return $renderer;
},
];

```

## Usage with any PSR-7 Project

Expand Down

0 comments on commit 33bc081

Please sign in to comment.