set Theme not just request wise


i have the problem, that i wanna set a Theme using the provided setTheme method from the Application Component. Works pretty good, but the theme is set for one request only.

Is there any way to set a theme permanently?

Or any application wide event i can use to set the theme for every request. I think i could use the beforeRequest Method of the application component, but don't know how to register an eventlistener.

Any help would be really appreciated.

Cheers Christian

This is a little example, on how to change the theme of your application, if requested from an iPhone:


	// behaviors

	'behaviors' => array(

		'onbeginRequest' => array(

			'class' => 'application.components.Startupbehavior',





class Startupbehavior extends Cbehavior


	public function attach($owner)


		// set the event callback

		$owner->attachEventHandler('onbeginRequest', array($this, 'beginRequest'));



	 * This method is attached to the 'onbeginRequest' event above.


	public function beginRequest(CEvent $event)






Hope that works for you. :)

Great. Works as expected. Although I find setting the theme on each request is a bit of a hassle.


You guys getting the following errors when applying the excellent code above?

PHP Error


include(Cbehavior.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Source File


Solution below;

Note ‘Cbehavior’ must be ‘CBehavior’!! I’ve add *'s to keep the cap B. The forum drops the case of ‘B’ to ‘b’ and breaks the above code. Took me a few hours to realise this ‘gotcha’!!

Where I found evidence for my issues…