Questa estensione e' un po'esagerata, cambia tutti gli url.
Io faccio una cosa simile a quella che fa sensorario, solo un po; piu' ordinata:
Ho una behavior per la application:
<?php
/**
* ApplicationConfigBehavior is a behavior for the application.
* It loads additional config paramenters that cannot be statically
* written in config/main
*/
class ApplicationConfigBehavior extends CBehavior
{
/**
* Declares events and the event handler methods
* See yii documentation on behaviour
*/
public function events()
{
return array_merge(parent::events(), array(
'onBeginRequest'=>'beginRequest',
));
}
/**
* Load configuration that cannot be put in config/main
*/
public function beginRequest()
{
// set the user language
//if the user choosed a language, we use the choosen one
if ($this->owner->user->getState('applicationLanguage'))
$this->owner->language=$this->owner->user->getState('applicationLanguage');
else
$this->owner->language='ru';
}
}
Che si include nel config main:
/* the behavior that loads other paramenters that can be loaded only runtime
* see protected/components/ApplicationConfigBehavior.php */
'behaviors'=>array(
'runTimeConfig'=>array(
'class'=>'ApplicationConfigBehavior'
)
),
Per cambiare la lingua io ho una form che manda ad una azione del site controller:
/**
* set the application language or the theme according to the choice of the user
* see protected/components/sectionMenu
* see protected/components/theme
*/
public function actionSettings()
{
if (isset($_POST['language']))
Yii::app()->user->setState('applicationLanguage',$_POST['language']);
$this->redirect($_POST['url']);
}
Grosso modo e' l'approccio di sensorario, solo che salviamo il valore nello user (perche' ci pensa Yii a metterlo in session) e carichiamo il valore nella onInit.