I want to send a parameter from controller to layout (i.e. main.php). But I am not able to get the param in main.php
I tried:
Controller Code:
$this->render('index',array('param' => $paramValue));
And this is how i was trying to get this in layout ie. main.php
$this->param
(as in yii 1)$param
But i am not able to get param value in layout. Can anyone tell me how to do this?
Thats because you are rendering
index.php
view, not themain.php
one.And
$param
this is how you get it in 1.1 version.UPD: If you want a param in your
main.php
layout declare it in yourController
class, and then you will be able to get it$this->param
this way.UPD2: Looks like in 2.0 version you need to declare param in a yii\web\View class. And access it via
Yii::$app->view->param
.directly calling $param u should get the value, try
yii\base\View has special $params property.
For example it's used for building breadcrumbs in default generated CRUD code templates with Gii.
You can set it like this before rendering:
Inside a controller you can set it like this:
Then it will be available in views (including main layout):
You can also find it in official guide.
I would like to suggest you some steps for this problem.
Check For parameter and If exist then use it.