Chaning param in the url


I’m wondering if there is a Yii way to change(or add) a param in the url accoring to defined set of route rules.

Speaking about my case:

I have an url: (and this might also be

I need to change(or add) language to the url to make it like

This is not working for me:

$this->createUrl($_SERVER['HTTP_REFERER'], array('lang'=>$_GET['newlang']))

where my route rules are:

'rules' => array(

  '<lang:('.$lang_rule.')>' => '',

  '<lang:('.$lang_rule.')>/<_c>' => '<_c>',

  '<lang:('.$lang_rule.')>/<_c>/<_a>/' => '<_c>/<_a>',

  '<lang:('.$lang_rule.')>/<_m>/<_c>/<_a>' => '<_m>/<_c>/<_a>',


// $lang_rule is a string like 'en|de'

p.s. Yes, I know how to do this in plain PHP in million ways, but I’m trying to find if this is possible with Yii.


Basically, what was needed, is to implement language changing.

So it was just solved this way:


$route = Yii::app()->urlManager->parseUrl(Yii::app()->getRequest());

$params = $_GET;

$params['lang'] = '{lang}';

$url = $this->createUrl('/'.$route,$params);


<script type="text/javascript">

    function changeLanguage(self)


        var url = '<?php echo urldecode($url) ?>';

        window.location = url.replace('{lang}', self.value);