J
J
jacksparrow2015-03-02 13:34:29
Yii
jacksparrow, 2015-03-02 13:34:29

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

2 answer(s)
V
Vit, 2015-03-02
@jacksparrow

It makes no sense to use ActiveForm for such a simple one-field form. Then the model is not needed.

M
Mikhail Pomytkin, 2015-03-02
@DanteXXI

Make a widget

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question