Make theme and layout option in your site

4 followers

This wiki article has not been tagged with a corresponding Yii version yet.
Help us improve the wiki by updating the version information.

Here i am writing code how to add option of theme change and layout change in your website.

Below are the steps you have to follow for this - Make Layout for each (i.e left,top,right)
- Make Css for each(as per your choice)
- Create a folder named theme and put all yor layout and other file for each theme respectivley
- In Css directory create directory for each theme and put all your css and js file in respective directory

Make table named theme where each theme name has its themeID,name

In Layout

<tr>
<td>
<table><?php echo CHtml::beginForm(); ?>
<tr><td>
<?php echo CHtml::label('Theme','Theme',array('class'=>'form-label')); ?></td></tr>
<tr><td>
<?php echo CHtml::dropdownlist('themeID', 'themeID',array(''=>'--Select--') 
+CHtml::listData(Theme::model()->findAll("status = 'A'",array('order' => 'theme_name',)), 'themeID', 'theme_name'),array('class'=>'span2 text','onchange'=>'this.form.submit();'));?>
</td></tr>  
<?php echo CHtml::endForm(); ?>
</table> </td>
<td><table>
<?php echo CHtml::beginForm(); ?>
<tr><td><?php echo CHtml::label('Layout','Layout',array('class'=>'form-label')); ?></td></tr>
<tr><td> 
<?php echo CHtml::dropdownlist('layoutID', 'layoutID',array(''=>'--Select--') +CHtml::listData(MenuLayout::model()->findAll(array('order' => 'layout_name',)), 'layoutID', 'layout_name'),array('class'=>'span2 text','onchange'=>'this.form.submit();'));?>
</td></tr>
<?php echo CHtml::endForm(); ?>
</table> </td>
</tr>
 
 
In Controller
 
public $theme;
 
        public function init()
        {
           $this->userID=Yii::app()->user->id;
            if(empty($this->userID)){
                $this->redirect(Yii::app()->homeUrl);
            }
 
            Yii::app()->theme = Yii::app()->session['theme']; 
            if(!empty(Yii::app()->session['layout'])){
            Yii::app()->layout = Yii::app()->session['layout'];
            }
            else{
                Yii::app()->layout = '//layouts/adminColumn';;
            }
            }
public $layout;

Be the first person to leave a comment

Please to leave your comment.

Write new article