A
A
Anchor002015-12-30 09:59:38
Yii
Anchor00, 2015-12-30 09:59:38

Yii2: Is it possible to make the parameters passed to View available in layout-e?

Parameters are passed from the Controller to the View like this:

return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'header' => 'lalala',
        ]);

After that, they become available, as appropriate variables, in the View. But NOT available in Layout. Actually a question. Is it possible to make these variables (the question is about them, i.e. "behind one" so that they are available AND in the Layout. About the fact that you need to transfer data from the controller to the layout through the view parameters, I know) were available in Layout?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
tigra, 2015-12-30
@tigroid3

just put similar layout'a content into the widget) and you won't need to do complicated manipulations

N
Nikita, 2015-12-30
@bitver

This is done through the View parameters, although you can get confused and render without layout, and write the layout itself and the $view render method in the view, then additionally pass a parameter, for example, 'view' => 'index'. But it is necessary to deepen the folder structure apparently.

M
maks280795, 2015-12-30
@maks280795

I searched for you on google, like what you need: stackoverflow.com/questions/28038912/how-to-pass-p...

I
Ilya Beloborodov, 2015-12-30
@kowap

In the parent controller (in the controller that inherits the current controller):
In the action that renders the view:
And now in the main template (layout) output like this:
echo $this->params;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question