class StartupBehavior extends CBehavior{
public function attach($owner){
$owner->attachEventHandler('onBeginRequest', array($this, 'beginRequest'));
}
public function beginRequest(CEvent $event){
$language=Yii::app()->request->getPreferredLanguage();
if ($language=='en_us')
$language='de';
Yii::app()->language=$language;
}
}
The problem is that my application breaks and i can’t debug. No erors, no warnings,nothing.
Check your http server logs, if there is a fatal error in PHP it doesn’t get logged in application log and your PHP configuration may prevent it from displaying to the user.
Anyway, I do language detection like this, saved in components/ApplicationConfigBehavior.php:
<?php
/**
* ApplicationConfigBehavior is a behavior for the application.
* It loads additional config parameters that cannot be statically
* written in config/main
*/
class ApplicationConfigBehavior extends CBehavior
{
/**
* Declares events and the event handler methods
* See yii documentation on behavior
*/
public function events() {
return array_merge(parent::events(), array(
'onBeginRequest'=>'beginRequest',
));
}
public function beginRequest() {
// or however you'd like to do it
// $this->processOption('language', 'language', 'applicationLanguage', array_keys($availableLanguages), Yii::app()->getRequest()->getPreferredLanguage());
return true;
}
}