Make theme and layout option in your site

0 0
4
Viewed: 19 556 times
Version: Unknown (update)
Category: How-tos
Written by: Narender Negi Narender Negi
Updated by: trond trond
Created: Aug 6, 2013
Updated: 13 years ago

You are viewing revision #4 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#3)

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;