Undefined property: CWebApplication::$lang

The code which causes problem is


if(isset($params['lang']) && ($params['lang']==Yii::app()->lang->default))

This code is from UrlManager.php:


class UrlManager extends CUrlManager

{

    public function createUrl($route,$params=array(),$ampersand='&')

    {

        if(isset($params['lang']) && ($params['lang']==Yii::app()->lang->default))

            unset($params['lang']);

        elseif(!isset($params['lang']) && Yii::app()->lang->isDifferent())

            $params['lang'] = Yii::app()->lang->current;


    return parent::createUrl($route,$params,$ampersand);

    }

}

UrlManager::createUrl method is called from LanguageSwitcherWidget.php


class LanguageSwitcherWidget extends CWidget

{

    public $template='link'; //select

    public function init()

    {

        if(count(Yii::app()->lang->data)<2) return;


        $links = array();

                $params = $_GET;

        foreach(Yii::app()->lang->data as $key => $value)

        {

            $params['lang']=$key;

            $links[$key] = $this->owner->createUrl('', $params);

        }

        $this->render($this->template, compact('links'));

    }

}

Here is components part of config file:


'lang' => [

                'class' => 'core.components.LanguageComponent',

            ],

'urlManager' => [

                'class' => 'UrlManager',

                'urlFormat' => 'path',

                'showScriptName' => false,

                'urlSuffix' => '/',

                'rules' => [

                    '<lang:\w{2}>/<controller>/<action>/*'=>'<controller>/<action>',

                    '<lang:\w{2}>'=>'/',

                ],

            ],

If I add lang to preload everything works fine.

What exactly is the problem here?

Can U please explain what is your issue here?

Can U please explain what is your issue here?

Buy fifa 15 coins

This issue is about Yii’s wrong error message when component is accessed inside the same component.

Full story is here: github.com/yiisoft/yii/issues/3677.