"how to pass param from controller to layout in yii2" Answer’s

0

yiibaseView 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.

Wednesday, March 31, 2021
 
Norgul
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share