Created
May 31, 2011 23:36
-
-
Save samdark/1001489 to your computer and use it in GitHub Desktop.
Yii: switching theme based on view name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Q: | |
* | |
* Hi, could please add this feature please. Here is my case, I have two themes | |
* and I have modules. How can one set each view file in the modules to use | |
* either one of the themes. Such if the view is admin use backoffice theme and | |
* if view is index use siteNew theme. I so someting like setBasePath and | |
* setBaseUrl but I don not know where they should be exactly. | |
* | |
* A: | |
* | |
* 1. Use SmartThemeController as a base controller (instead of Controller). | |
* 2. Render views as always with $this->render('viewName'). | |
*/ | |
class SmartThemeController extends CController | |
{ | |
public function render($view,$data=null,$return=false) | |
{ | |
// prior to rendering we need to check if we need to | |
// switch theme | |
switch($view){ | |
case 'admin': | |
Yii::app()->setTheme('backoffice'); | |
break; | |
case 'index': | |
Yii::app()->setTheme('siteNew'); | |
break; | |
} | |
return parent::render($view,$data,$return); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment