Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions guide/en/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The definitive guide to Yii 3.0

We release this guide under the [Terms of Yii Documentation](https://www.yiiframework.com/license#docs).

Check warning on line 3 in guide/en/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/README.md#L3

[Microsoft.We] Try to avoid using first-person plural like 'We'.
Raw output
{"message": "[Microsoft.We] Try to avoid using first-person plural like 'We'.", "location": {"path": "guide/en/README.md", "range": {"start": {"line": 3, "column": 1}}}, "severity": "WARNING"}

Introduction +
------------
Expand Down Expand Up @@ -46,7 +46,7 @@
Handling requests +
-----------------

* [Routing and URL generation](runtime/routing.md) +

Check warning on line 49 in guide/en/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/README.md#L49

[Microsoft.GeneralURL] For a general audience, use 'address' rather than 'URL'.
Raw output
{"message": "[Microsoft.GeneralURL] For a general audience, use 'address' rather than 'URL'.", "location": {"path": "guide/en/README.md", "range": {"start": {"line": 49, "column": 16}}}, "severity": "WARNING"}
* [Request](runtime/request.md) +
* [Response](runtime/response.md) +
* [Sessions](runtime/sessions.md) +
Expand All @@ -58,20 +58,18 @@
-----

* [Views](views/view.md) -
* [Widgets](views/widget.md) -
* [Assets](views/asset.md) -
* [Working with client scripts](views/client-scripts.md) -
* [Theming](views/theming.md) -
* [Template engines](views/template-engines.md) -
* [View injections](views/view-injections.md) +

* [Scripts, styles and metatags](views/script-style-meta.md)
* [Assets](views/asset.md) -
* [Widgets](views/widget.md) -

Working with databases +-
----------------------

* [Database access objects](db-dao.md): Connecting to a database, basic queries, transactions, and schema manipulation
* [Query builder](db-query-builder.md): Querying the database using a simple abstraction layer
* [Active record](db-active-record.md): The Active Record ORM, retrieving and manipulating records, and defining relations

Check notice on line 72 in guide/en/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/README.md#L72

[Microsoft.Acronyms] 'ORM' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'ORM' has no definition.", "location": {"path": "guide/en/README.md", "range": {"start": {"line": 72, "column": 59}}}, "severity": "INFO"}
* [Migrations](databases/db-migrations.md): +

Getting data from users -
Expand Down Expand Up @@ -113,7 +111,7 @@
* [HTTP caching](caching/http.md) -


REST APIs -

Check warning on line 114 in guide/en/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/README.md#L114

[Microsoft.HeadingAcronyms] Avoid using acronyms in a title or heading.
Raw output
{"message": "[Microsoft.HeadingAcronyms] Avoid using acronyms in a title or heading.", "location": {"path": "guide/en/README.md", "range": {"start": {"line": 114, "column": 1}}}, "severity": "WARNING"}

Check notice on line 114 in guide/en/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/README.md#L114

[Microsoft.Acronyms] 'REST' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'REST' has no definition.", "location": {"path": "guide/en/README.md", "range": {"start": {"line": 114, "column": 1}}}, "severity": "INFO"}

Check notice on line 114 in guide/en/README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/README.md#L114

[Microsoft.Headings] 'REST APIs -' should use sentence-style capitalization.
Raw output
{"message": "[Microsoft.Headings] 'REST APIs -' should use sentence-style capitalization.", "location": {"path": "guide/en/README.md", "range": {"start": {"line": 114, "column": 1}}}, "severity": "INFO"}
-----------

* [Quick start](rest/quick-start.md)
Expand Down
5 changes: 5 additions & 0 deletions guide/en/views/asset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Assets

> [!NOTE]
> [← Scripts, styles and metatags](script-style-meta.md) |
> [Widgets →](widget.md)
5 changes: 5 additions & 0 deletions guide/en/views/script-style-meta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Scripts, styles and metatags

> [!NOTE]
> [← View injections](view-injections.md) |
> [Assets →](asset.md)
69 changes: 69 additions & 0 deletions guide/en/views/template-engines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Template engines

Yii views support multiple template engines as well as custom engines. By default, Yii uses the PHP engine.

Check notice on line 3 in guide/en/views/template-engines.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/template-engines.md#L3

[Microsoft.Vocab] Verify your use of 'as well as' with the A-Z word list.
Raw output
{"message": "[Microsoft.Vocab] Verify your use of 'as well as' with the A-Z word list.", "location": {"path": "guide/en/views/template-engines.md", "range": {"start": {"line": 3, "column": 45}}}, "severity": "INFO"}
Additionally, [Twig](https://twig.symfony.com/) is available.

## PHP

Check notice on line 6 in guide/en/views/template-engines.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/template-engines.md#L6

[Microsoft.Headings] 'PHP' should use sentence-style capitalization.
Raw output
{"message": "[Microsoft.Headings] 'PHP' should use sentence-style capitalization.", "location": {"path": "guide/en/views/template-engines.md", "range": {"start": {"line": 6, "column": 4}}}, "severity": "INFO"}

Check warning on line 6 in guide/en/views/template-engines.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/template-engines.md#L6

[Microsoft.HeadingAcronyms] Avoid using acronyms in a title or heading.
Raw output
{"message": "[Microsoft.HeadingAcronyms] Avoid using acronyms in a title or heading.", "location": {"path": "guide/en/views/template-engines.md", "range": {"start": {"line": 6, "column": 4}}}, "severity": "WARNING"}

PHP engine is available by default. The following is the basic template syntax:

```php
<?php

declare(strict_types=1);

use Yiisoft\Html\Html;

/**
* @var App\Blog\Post[] $posts
*/
?>

Posts:

<dl>
<?php foreach ($posts as $post): ?>
<dt>Title: <?= Html::encode($post->getTitle()) ?></dt>
<dd>Description: <?= Html::encode($post->getDescription()) ?></dd>
<?php endforeach; ?>
</dl>
```

At the very top of the template, you can define "uses" for classes to use and declare the type of variables

Check warning on line 32 in guide/en/views/template-engines.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/template-engines.md#L32

[Microsoft.Adverbs] Remove 'very' if it's not important to the meaning of the statement.
Raw output
{"message": "[Microsoft.Adverbs] Remove 'very' if it's not important to the meaning of the statement.", "location": {"path": "guide/en/views/template-engines.md", "range": {"start": {"line": 32, "column": 8}}}, "severity": "WARNING"}
so the IDE understands them. The rest is the PHP code.

> [!WARNING]
> `<?=` or `echo` doesn't automatically encode variables for safe use with HTML and you should take care of it by using
> `Html::encode()`.

If you need a sub-view, you can use it like this:

```php
<?php

declare(strict_types=1);

/**
* @var Yiisoft\View\View $this
* @var App\Blog\Post[] $posts
*/
?>

Title

<?= $this->render('blog/posts', ['posts' => $posts]) ?>
```

### See also

- [yiisoft/view docs](https://github.com/yiisoft/view/blob/master/docs/guide/en/README.md).
-

## Twig

To use Twig, you need to install the [yiisoft/yii-twig](https://github.com/yiisoft/yii-twig).


> [!NOTE]
> [← Views](view.md) |
> [View injections →](view-injections.md)
13 changes: 12 additions & 1 deletion guide/en/views/view-injections.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# View injections

The view injections are designed to provide a standardized way to pass parameters to the common layer

Check notice on line 3 in guide/en/views/view-injections.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view-injections.md#L3

[Microsoft.Passive] 'are designed' looks like passive voice.
Raw output
{"message": "[Microsoft.Passive] 'are designed' looks like passive voice.", "location": {"path": "guide/en/views/view-injections.md", "range": {"start": {"line": 3, "column": 21}}}, "severity": "INFO"}
of views in an application. Implementing this interface allows developers to manage the data that will be available
of views in an application. It allows developers to manage the data that will be available

Check notice on line 4 in guide/en/views/view-injections.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view-injections.md#L4

[Microsoft.Vocab] Verify your use of 'allows' with the A-Z word list.
Raw output
{"message": "[Microsoft.Vocab] Verify your use of 'allows' with the A-Z word list.", "location": {"path": "guide/en/views/view-injections.md", "range": {"start": {"line": 4, "column": 32}}}, "severity": "INFO"}
across various views, ensuring flexibility and reusability of code.

The view injections could be used if you require `yiisoft/yii-view-renderer` package:

Check notice on line 7 in guide/en/views/view-injections.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view-injections.md#L7

[Microsoft.Passive] 'be used' looks like passive voice.
Raw output
{"message": "[Microsoft.Passive] 'be used' looks like passive voice.", "location": {"path": "guide/en/views/view-injections.md", "range": {"start": {"line": 7, "column": 27}}}, "severity": "INFO"}


```sh
composer require yiisoft/yii-view-renderer
```

## Configuration

In config `params.php`:
Expand Down Expand Up @@ -57,10 +64,10 @@
],
```

## Using Separate Injections for Different Layouts

Check notice on line 67 in guide/en/views/view-injections.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view-injections.md#L67

[Microsoft.Headings] 'Using Separate Injections for Different Layouts' should use sentence-style capitalization.
Raw output
{"message": "[Microsoft.Headings] 'Using Separate Injections for Different Layouts' should use sentence-style capitalization.", "location": {"path": "guide/en/views/view-injections.md", "range": {"start": {"line": 67, "column": 4}}}, "severity": "INFO"}

If your application has multiple layouts, you can create separate parameter injections for each layout. This approach
allows you to tailor the parameters injected into each layout according to its specific needs, enhancing the flexibility

Check notice on line 70 in guide/en/views/view-injections.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view-injections.md#L70

[Microsoft.Vocab] Verify your use of 'allows' with the A-Z word list.
Raw output
{"message": "[Microsoft.Vocab] Verify your use of 'allows' with the A-Z word list.", "location": {"path": "guide/en/views/view-injections.md", "range": {"start": {"line": 70, "column": 1}}}, "severity": "INFO"}
and maintainability of your application.

Create your custom ViewInjection for a specific layout:
Expand All @@ -81,7 +88,7 @@
}
```

Add your new injection to `params.php` under specific layout name. In the following example, it is `@layout/cart`:

Check failure on line 91 in guide/en/views/view-injections.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view-injections.md#L91

[Microsoft.Contractions] Use 'it's' instead of 'it is'.
Raw output
{"message": "[Microsoft.Contractions] Use 'it's' instead of 'it is'.", "location": {"path": "guide/en/views/view-injections.md", "range": {"start": {"line": 91, "column": 94}}}, "severity": "ERROR"}

```php
'yiisoft/yii-view' => [
Expand All @@ -101,3 +108,7 @@
],
],
```

> [!NOTE]
> [← Template engines](template-engines.md) |
> [Scripts, styles and metatags →](script-style-meta.md)
55 changes: 55 additions & 0 deletions guide/en/views/view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Views

Yii3 views could be used by requiring the `yiisoft/view` package:

Check notice on line 3 in guide/en/views/view.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view.md#L3

[Microsoft.Passive] 'be used' looks like passive voice.
Raw output
{"message": "[Microsoft.Passive] 'be used' looks like passive voice.", "location": {"path": "guide/en/views/view.md", "range": {"start": {"line": 3, "column": 18}}}, "severity": "INFO"}

```sh
composer require yiisoft/view
```

The package provides template rendering abstraction supporting layout-view-subview hierarchy, custom renderers
with PHP-based as default, and more.

Usage is the following:

```php
```

If you're building a web application, you should require the `yiisoft/yii-view-renderer` package as well:

```sh
composer require yiisoft/yii-view-renderer
```

It provides some extra web-specific functionality and adds compatibility with PSR-7 interfaces and could be used like

Check notice on line 23 in guide/en/views/view.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view.md#L23

[Microsoft.Acronyms] 'PSR' has no definition.
Raw output
{"message": "[Microsoft.Acronyms] 'PSR' has no definition.", "location": {"path": "guide/en/views/view.md", "range": {"start": {"line": 23, "column": 79}}}, "severity": "INFO"}

Check notice on line 23 in guide/en/views/view.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view.md#L23

[Microsoft.Passive] 'be used' looks like passive voice.
Raw output
{"message": "[Microsoft.Passive] 'be used' looks like passive voice.", "location": {"path": "guide/en/views/view.md", "range": {"start": {"line": 23, "column": 106}}}, "severity": "INFO"}
the following:

```php
<?php

declare(strict_types=1);

namespace App\Controller\HomePage;

use Psr\Http\Message\ResponseInterface;
use Yiisoft\Yii\View\Renderer\ViewRenderer;

final readonly class Action
{
public function __construct(
private ViewRenderer $viewRenderer,
) {}

public function __invoke(): ResponseInterface
{
return $this->viewRenderer->render(__DIR__ . '/template', [
'name' => 'Sergei',
'surname' => 'Predvoditelev',
]);
}
}
```

In both cases a template file should be supplied. The template syntax depends on the template engine used.

Check notice on line 52 in guide/en/views/view.md

View workflow job for this annotation

GitHub Actions / vale

[vale] guide/en/views/view.md#L52

[Microsoft.Passive] 'be supplied' looks like passive voice.
Raw output
{"message": "[Microsoft.Passive] 'be supplied' looks like passive voice.", "location": {"path": "guide/en/views/view.md", "range": {"start": {"line": 52, "column": 38}}}, "severity": "INFO"}

> [!NOTE]
> [Template engines →](template-engines.md)
5 changes: 5 additions & 0 deletions guide/en/views/widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Widgets


> [!NOTE]
> [← Assets](asset.md)
Loading