I want my site to be able to use multiple themes. I checked the documentation, cookbook and some other resources but the information that i found was either vague or not helpful at all regarding this matter.
inside testapp/protected/themes
i see a folder called classic which i assume is a theme, i made a copy of the classic folder inside the theme directory and renamed it to bluebird,
so far i think those should be 2 themes that the application could possibly use…
i then copied the contents of testapp/protected/views to the views folder inside both classic and bluebird… then deleted the content from testapp/protected/views…
i then edited protected/config/main.php as follows
The view folder is still present in the protected folder, It’s just that i moved the php files to /themes/themename/views
If what you say is the case, then my question should be how do i get yii to search the themes folder for view files instead of the protected/views folder…
(PS. i think the C before the class names stands for class like CController means ClassController ).
that i do not know, have myself been trying to figure out, eventually went with a master layout file in the protected/views/ folder that contains all the other view files.
I haven’t actually implemented it yet so i cant show you the source but i can give you a pretty good idea of what to do…
first thing create a child of CController in your components directory so you should have something like this
class BaseController extends CController
{
public funtion init()
{
$thid->_setTheme();
}
public funtion _setTheme()
{
$defaultTheme = 'classic';
if(isset($_POST['theme']))
{
$theme = $_POST['theme'];
//set theme cookie to $theme here ?
}else if($_COOKIE['theme']))
{
$theme = $_COOKIE['theme'];
}else{
$theme = $defaultTheme;
}
Yii::app()->setTheme($theme);
}
}
and make all your controllers children of BaseController like
class SiteController extends BaseController
{
public function actionIndex()
{
}
}
copy the contents of protected/views to themes/classic/views
then you can remove the files from protected/views but i don’t recommend removing the actual folders
you can then make the default theme classic, then you can make copies of classic and rename them to represent other themes…
That’s not elegant or tested code but it should give you an idea of what to do. It’s not necessary to set the theme property in the config file unless you really just want to use 1 theme.
If you are having trouble just ask and i’ll try to give a better explanation.