How to use a Block in other views?

How to reuse a Block made in the

view1: @app/views/config/index.php

by the

view2. @app/views/profile/index.php


  1. works in view1:

Yii::$app->view->params['menuConfig'] = $this->blocks['menuConfig'];

echo Yii::$app->view->params['menuConfig'];

  1. did’nt work in view2:

echo Yii::$app->view->params['menuConfig'];

because the Yii::$app->view->params[‘menuConfig’] was empty(checked with var_damp).

  1. same result by using:


By the way, the Block shoudn’t be passed through view1->layout(main.php)->view2.

Thanks in advance.


did you consider creating a widget instead of blocks

I just want to known how to passed the Blocks between the views easily, why the $app->view->params and $app->params[‘menuConfig’] are not global.