Which Approach Is Correct For Onbeginrequest

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

		}

		

	}

}

?>

I can’t see anything wrong with this. If you like it better and don’t mind the static context, do it this way.

Thanks for that - just wanted to check that there was nothing horrendously wrong with the second approach. Not sure what the pros/cons for using (over use of) static methods are (am a technical user!) maybe a performance hit?