Js Configuration File


I need to call site baseUrl in javascript variable or i need to create one javascript file in which all yii congurations will be avaiable like urlManager is enabled or not.

Anyone has idea to do this

Yii::app()->clientScript->registerScript( 'config#', 'window.yiiBaseUrl = ' . json_encode( Yii::app()->baseUrl ) . ';', CClientScript::POS_HEAD );

I did something similar, but overrode CClientScript to add a new method:

class ClientScript extends CClientScript


    public function registerVariable($name, $value)



                "var $name = " . CJavaScript::encode($value, true) . ';',


        return $this;



It just makes it a bit easier to call:

Yii::app()->clientScript->registerVariable('yiiBaseUrl', Yii::app()->baseUrl);

Attaching to the window as redguy suggested might be better than having a global variable.