Calling function to set global controller variables


I’m new to Yii but not to PHP. I’m using the latest version of Yii. Its awesome!

I’m building an App that heavily uses themes. What is the best way to set a load of variables for an entire controller (including which theme we are going to use).

I noticed filters but wasnt sure how these worked. I tried creating a filter like this

public function filterSetGlobalVars($filterChain)



    $this->somethingelse = 'more';



How does this filter get called without me doing it in each method of the controller. Perhaps I’m doing this all wrong and filters are not the right choice.

Any help greatly appreciated.

[font=arial, verdana, tahoma, sans-serif][size=2]

Override CController::init() in your controller class.


Themes are (mainly) used for changing the appearance of the entire application. It’s much easier to use layouts when you want to change appearance on a per-controller basis.