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.
<?php
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)
{
if(stripos(CHttpRequest::getUserAgent(),'iPhone'))
Yii::app()->theme='iphone';
}
}
You guys getting the following errors when applying the excellent code above?
PHP Error
Description
include(Cbehavior.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
Source File
C:\XAMPP\xampp\yii\framework\YiiBase.php(338)
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’!!