Controller Themes

I have broken up my application into sections such as public, private, admin etc… and have controllers for each, i also want to have a different theme for each section by having themes/public, themes/private, themes/admin.

Obviously I can activate each theme via protected/config/main.php with the following code

‘theme’ => ‘public/public_theme_1.0.0’

How do i switch between themes on a controller basis so as the user navigates to each section the controller updates the theme?


Ok i just worked it out, in the AdminController class I created a private function called setTheme()

private function setTheme()


return Yii::app()->theme='admin/admin_theme_1.0.0';


then in each action render call i put $this->render(‘index’, $this->setTheme());

Does anyone know a shorter more global way of doing this without updating each render params?

You can configure themes path and url in the themesManager:

class AdminController extends CController


    public function init()


        Yii::app()->themeManager->basePath .= '/admin';

        Yii::app()->themeManager->baseUrl .= '/admin';

        Yii::app()->theme = 'admin_theme_1.0.0'; // You can set it there or in config or somewhere else before calling render() method.



cool, a nice way :lol:

dynamic change the basePath/Url is simple and effective !

Perfect, thanks for the advice, much cleaner. :D