php - Passing language as variable as url parameter in yii -


i'm having problem yii seems simple can't find appropriate solution it. need i18n in web page , i'm using yii, have translations done, found it's possible change language in controller class that:

class controller extends ccontroller {     function init() {         parent::init();         if(isset($_get['lang'])) {             yii::app()->language = 'lt';         }     } } 

everything ok, language parameter lost when url doesn't contain language parameter. 1 way around adding parameter in urls across whole site, doesn't seem solution.

is there more static way of passing parameter? maybe option in urlmanager in yii? or maybe there way of changing language more dynamically?

a simple solution use session data remember user's language choice across pages:

function init() {     parent::init();     $app = yii::app();      // if "lang" specified, remember     if(isset($_get['lang'])) {         $app->session['language'] = 'lt';     }      // if remember language put in use     if($app->session->contains('language')) {         $app->language = $app->session['language'];     }  } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -