Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the ViewRenderer use statement, add hydrator install guidance … #227

Merged
merged 1 commit into from
Jan 30, 2025
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
22 changes: 17 additions & 5 deletions guide/en/start/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ The `EchoForm` class has `$message` property and related getter.
## Using the form <span id="using-form"></span>

Now, that you have a form, use it in your action from "[Saying Hello](hello.md)".

You also need to install hydrator package

```
composer require yiisoft/hydrator
```

Here's what you end up with in `/src/Controller/EchoController.php`:

```php
Expand All @@ -51,7 +58,7 @@ declare(strict_types=1);
namespace App\Controller;

use App\Form\EchoForm;
use Yiisoft\Yii\View\ViewRenderer;
use Yiisoft\Yii\View\Renderer\ViewRenderer;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Hydrator\Hydrator;
Expand Down Expand Up @@ -139,7 +146,7 @@ use Yiisoft\Html\Html;

<?= Html::submitButton('Say') ?>

<?= '</form>' ?>
<?= Html::form()->close() ?>
```

If a form has a message set, you're displaying a box with the message. The rest if about rendering the form.
Expand Down Expand Up @@ -215,7 +222,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Http\Method;
use Yiisoft\Validator\Validator;
use Yiisoft\Yii\View\ViewRenderer;
use Yiisoft\Yii\View\Renderer\ViewRenderer;
use Yiisoft\Hydrator\Hydrator;

class EchoController
Expand Down Expand Up @@ -267,6 +274,11 @@ class EchoForm
{
return $this->message;
}

public function getFormName()
{
return (new \ReflectionClass($this))->getShortName();
}

}
```
Expand Down Expand Up @@ -301,7 +313,7 @@ use Yiisoft\Html\Html;
<?php endif ?>

<?= Html::form()
->post($urlGenerator->generate('print/form'))
->post($urlGenerator->generate('echo/say'))
->csrf($csrf)
->open() ?>

Expand All @@ -315,7 +327,7 @@ use Yiisoft\Html\Html;

<?= Html::submitButton('Say') ?>

<?= '</form>' ?>
<?= Html::form()->close() ?>
```

## Trying it Out <span id="trying-it-out"></span>
Expand Down
2 changes: 1 addition & 1 deletion guide/en/start/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ declare(strict_types=1);

namespace App\Controller;

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

Expand Down
Loading