Skip to content

Commit

Permalink
Improve package configuration parameters (#119)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Makarov <[email protected]>
  • Loading branch information
vjik and samdark authored Jun 19, 2024
1 parent 3eab97b commit 2b194d5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## 7.0.0 under development

- Chg #115: Only a full path can now be used as a layout (@vjik)
- Chg #116, #117, #118: Rename package to `yiisoft/yii-view-renderer` (@vjik)
- Chg #116, #117, #118: Rename package to `yiisoft/yii-view-renderer` (@vjik)
- Chg #119: Change package configuration parameters `viewPath` and `layout` to null (@vjik)

## 6.1.1 June 06, 2024

Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $viewRenderer = new \Yiisoft\Yii\View\Renderer\ViewRenderer(
$aliases,
$webView,
'/path/to/views', // Full path to the directory of view templates or its alias.
'layouts/main', // Default is null, which means not to use a layout.
'layouts/main.php', // Default is null, which means not to use a layout.
);

// Rendering a view with a layout.
Expand Down Expand Up @@ -297,6 +297,23 @@ $viewRenderer = $viewRenderer->withLocale('de_DE');

For more information about localization, see at the [localization](https://github.com/yiisoft/view/blob/master/docs/guide/en/basic-functionality.md#localization) section in [yiisoft/view](https://github.com/yiisoft/view) package.

### [Yii Config](https://github.com/yiisoft/config) parameters

```php
'yiisoft/yii-view-renderer' => [
// The full path to the directory of views or its alias.
// If null, relative view paths in `ViewRenderer::render()` is not available.
'viewPath' => null,

// The full path to the layout file to be applied to views.
// If null, the layout will not be applied.
'layout' => null,

// The injection instances or class names.
'injections' => [],
],
```

## Documentation

- [Internals](docs/internals.md)
Expand Down
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ application when you upgrade the package from one version to another.
- Change layout value that passed to `ViewRenderer` constructor and `withLayout()` method to full path.
- Change namespace `Yiisoft\Yii\View\*` to `Yiisoft\Yii\View\Renderer\*`.
- Rename package configuration parameters key from "yiisoft/yii-view" to "yiisoft/yii-view-renderer".

- Now configuration parameters `viewPath` and `layout` is null by default. If your application requires other values add
them to the configuration parameters on application level. For example:

```php
'yiisoft/yii-view-renderer' => [
'viewPath' => '@views',
'layout' => '@layout/main.php',
],
```
22 changes: 10 additions & 12 deletions config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@

return [
'yiisoft/yii-view-renderer' => [
'viewPath' => '@views',
'layout' => '@layout/main',
'injections' => [
// Use for add Csrf parameter to all views
// Reference::to(CsrfViewInjection::class),
// or
// DynamicReference::to(function (ContainerInterface $container) {
// return $container
// ->get(CsrfViewInjection::class)
// ->withParameter('mycsrf');
// }),
],
// The full path to the directory of views or its alias.
// If null, relative view paths in `ViewRenderer::render()` is not available.
'viewPath' => null,

// The full path to the layout file to be applied to views.
// If null, the layout will not be applied.
'layout' => null,

// The injection instances or class names.
'injections' => [],
],
'yiisoft/yii-debug' => [
'collectors.web' => [
Expand Down
3 changes: 2 additions & 1 deletion src/ViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ final class ViewRenderer implements ViewContextInterface
* @param DataResponseFactoryInterface $responseFactory The data response factory instance.
* @param Aliases $aliases The aliases instance.
* @param WebView $view The web view instance.
* @param string|null $viewPath The full path to the directory of views or its alias.
* @param string|null $viewPath The full path to the directory of views or its alias. If null, relative view paths
* in {@see ViewRenderer::render()} are not available.
* @param string|null $layout The full path to the layout file to be applied to views. If null, the layout will
* not be applied.
* @param array $injections The injection instances or class names.
Expand Down

0 comments on commit 2b194d5

Please sign in to comment.