O
O
Oleg Trubin2014-12-12 22:37:49
Yii
Oleg Trubin, 2014-12-12 22:37:49

[Yii2] How to make multiple views in one layout?

Hello.
The task is to make a list of entities on one page with the ability to delete, change and add.
Those. at the top is a list (table) of these entities, below it is a form through which you can add a new one.
If it were necessary on different pages, then it would be clear how to do it - through Controller-render with the desired view and model.
Here is the question: how can I display 2 views in one layout (a list and an add form)
Maybe I explained it chaotically, but I hope it's clear.
THANK YOU in advance to all who respond :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Zelenin, 2014-12-13
@zelenin

in the controller form the data you need
$model = new Model;
$form = new Form;
$list = Model::find()->all();
pass everything to the view
$this->render('view',['model'=>$model,'form'=>$form,'list'=>$list]);
in the view, do whatever you want - display lists, grids, forms, whatever. Add. include files via <?= $this->render('_form', ['model' => $model]) ?> inside view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question