Make theme and layout option in your site

0 0
4
Viewed: 19 558 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 #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#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

<?php echo CHtml::label('Theme','Theme',array('class'=>'form-label')); ?>
<?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();'));?>
<?php echo CHtml::label('Layout','Layout',array('class'=>'form-label')); ?>
<?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();'));?>

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;