How to change the language

I have done all described in the cookbook/26 but dropdown language list is not work.



class MyController extends CController


    function init()



        $app = Yii::app();

        if (isset($_POST['_lang']))


            $app->language = $_POST['_lang'];

            $app->session['_lang'] = $app->language;


        else if (isset($app->session['_lang']))


            $app->language = $app->session['_lang'];







class LangBox extends CWidget


    public function run()


        $currentLang = Yii::app()->language;

        $this->render('langBox', array('currentLang' => $currentLang));




<?php echo CHtml::form() ?>

    <div id="langdrop">

        <?php echo CHtml::dropDownList('_lang', $currentLang, array(

            'en' => 'English', 'ru' => 'Русский'), array('submit' => '')) ?>




‘sourceLanguage’ => ‘en’,

‘language’ => ‘ru’,

  1. messages/ru/main.php


return array('Home' => 'Главная',);

I can change language when I set in the config/main.php ‘language’ => ‘en’,

, but dropdown selector is not work. Where is my mistake?

Can anybody help me, please.

I use this code to change the language of my site:

class SiteController extends Controller {

    public function beforeAction() {

        if ( isset($_GET['lang']) )

            Yii::app()->language = $_GET['lang'];

        return true;


And it works.

Are you shure, that you use POST method in the components/views/langBox.php ?

May be, you have not to write

$app = Yii::app(); $app->language = $_POST['_lang'];

, but

Yii::app()->language = $_POST['_lang'];

Yaroslav, thank you for your reply.

How on the base of your code I can set dropdown selector?

I need working solution.

Please delete my post.

It was my mistake. The method is work.