A
A
Alexander2017-01-08 11:07:03
Yii
Alexander, 2017-01-08 11:07:03

Passing data from the controller to the template (layout). How to correctly implement in yii2?

Up to this point, I used $this->view->params to pass data from view to layout, but now there is a need to use a rather large amount of data in the template, namely to implement a list of friends. To do this, you need to get all the necessary information about these users from the database in the controller and transfer it to layout. And no matter what view is currently being rendered. It seems to me that $this->view->params for this is a rather clumsy solution. What is usually done in such situations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
melnikov_m, 2017-01-08
@LordGuard

You can wrap this custom logic in a widget and then it will be connected in the template in one line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question