Assuming you want to do something about the Theme on the fly (which for example is passed as theme=value in the uri) - the standard approach that I’ve come across in this forum is as below:
// behaviors - in config/main.php
'behaviors' => array(
'onBeginRequest' => array(
'class' => 'application.components.ThemeRequest'
),
),
along with something like below in components
<?php
class ThemeRequest extends CBehavior
{
public function attach($owner)
{
$owner->attachEventHandler('onBeginRequest', array($this, 'switchThemes'));
}
public function switchThemes($event)
{
$theme = Yii::app()->request->getParam('theme', 'classic');
if ( $theme ) {
Yii::app()->user->setState('theme', $theme);
// some controller takes action depending on value of session var
}
}
}
?>
What I would like to know is if there is anything wrong in doing it this way - seems to work
// events - in config/main.php
'onException' => array('DemoDisabledError', 'handler'),
'onBeginRequest' => array('ThemeChanger', 'handler'),
and in components something like
<?php
class ThemeChanger
{
public static function handler(CEvent $event) {
$theme = Yii::app()->request->getParam('theme', 'classic');
if ( $theme ) {
Yii::app()->user->setState('theme', $theme);
// some controller takes action depending on value of session var
}
}
}
?>