Answer the question
In order to leave comments, you need to log in
What is the correct way to place one form on all pages in YII 2?
There was a problem, it is necessary to place the form adding a text line on all pages. But the form requires a model, and in order to place it in the layout it was necessary to add a crutch, tell me how to do it right.
<? if (!$model) {
$model = new \app\models\Name();
$form = ActiveForm::begin(['action' => '/name/search/']);
} else {
$form = ActiveForm::begin();
}
Answer the question
In order to leave comments, you need to log in
It makes no sense to use ActiveForm for such a simple one-field form. Then the model is not needed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question