Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

  1. $this->param (as in yii 1)
  2. $param

But i am not able to get param value in layout. Can anyone tell me how to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
370 views
Welcome To Ask or Share your Answers For Others

1 Answer

yiiaseView 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:

use Yii;

Yii::$app->view->params['customParam'] = 'customValue';

Inside a controller you can set it like this:

$this->view->params['customParam'] = 'customValue';

Then it will be available in views (including main layout):

/* @var $this yiiwebView */

echo $this->params['customParam'];

You can also find it in official guide.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...