How to pass param from controller to layout in YII2

后端 未结 6 1287
面向向阳花
面向向阳花 2020-12-05 01:30

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:



        
6条回答
  •  爱一瞬间的悲伤
    2020-12-05 02:21

    In Yii2 you can access your controller object from a view using $this->context for example if in your controller you set a parameter like this:

    public $title = 'My custom title';
    

    Then in your layout you can read it like this:

    $this->context->title
    

    It is explained in Yii documentation in section: Accessing Data in Views

提交回复
热议问题