Passing Var From Controller To Layout To Widget


I need to pass a variable to a widget which is called inside a layout file.

I understand that you can’t pass variables to layouts, so how do I get the variable to the widget?

Thanks in advance!

Any controller’s properties can be accessed in the layout, just use $this->property in your layout.

That works in a view but it doesn’t work work in a layout.

For anyone interested to solve this I had to bring the widget call into the view file. I would be interested to know if there’s any other way to do it however.

Hi please see forum

We’re talking the same term for ‘layout’, aren’t we? :)

It should work, try this:

class testController extends CController


  public $test = 'Hello';

  public function actionHello()


    return $this->render('view', ...);



echo $this->test in your layout, it should work.