Make theme and layout option in your site

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

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

In Controller

public $theme;
        public function init()
            Yii::app()->theme = Yii::app()->session['theme']; 
            Yii::app()->layout = Yii::app()->session['layout'];
                Yii::app()->layout = '//layouts/adminColumn';;
public $layout;

0 0
Viewed: 15 644 times
Version: Unknown (update)
Category: How-tos
Tags: layouts, theme
Written by: Narender Negi
Last updated by: trond
Created on: Aug 6, 2013
Last updated: 10 years ago
Update Article


View all history

Related Articles