language in url


i got this thing with multilanguage,

try to create application with language in Url.

try to use rules like


create URLmanager inset isue, real isue is how to get

<lang:\w+>, best is to get it in Controller init().

but, HOW? , try $_GET is empty, no parameters, and $this not very helpful.

for consistence i write here all codes

class AppUrlManager extends CUrlManager {

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







           elseif (!isset($route['language']))

           {  $route['language']=Yii::app()->getLanguage(); }


           {   Yii::app()->setLanguage($route['language']); }

           // var_dump($route);

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



------------------------------- SOLVED SOLUTION --------------------------

rules like that:(thanks to alex-w)




and aUrlManager extension like

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

    $route = Yii::app()->getLanguage().'/'.$route;

// NOT LIKE This : $route['lang']=Yii::app()->getLanguage(); 

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


effects :

will add your current app language to url any time call CreateUrl.

What url are you using?

I believe you need to make rules to account for all variants.





yes, and then what?

how can i read <lang:\w+> in constroller init()? or somehere else onoce to setup the language, like Yii:app()->setLanguage()?

Should be in $_GET[‘lang’] iirc.

some more manipulation a figure it out that when using it should be very careful especially with rules order.

now new question, i got this language at stage when i what it, how to automatically create paths with it

i use

class AppUrlManager extends CUrlManager {

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


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



// rules






and in path i literary have



this eite is relay an anomaly, i figure out that

basically it is "site" with changed first letter of passed language (in this case en_us)

i try other languages and get some , ‘bite’,‘lite’, etc and so on.

next thing i noteces if i use generator without real path such as


then its generate a genuine path with language inserted. like


what suggestions can be?

I have solved with this implementation of createUrl() method, that normally parse $_GET[language] and if find $_GET[new_lang] set new language to yii app, to permit to end users of change locale.

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


    if(isset($_GET['new_lang'])) {


    } else {



    $route = Yii::app()->getLanguage().'/'.$route;

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


I bumped into a problem with this technique.

Using the createAbsoluteUrl to create a url for an actual file on the server,

the language part interferes and makes the url invalid…

Lets say I want to make a url to:

It will make it

And of course a 404 will rise.

So there are cases where the language must not be added to the url…