Yii::app()->baseUrl and relative paths


using Yii::app()->baseUrl and Yii::app()->theme->baseUrl always generates an absolute path relative to the base URi, like:



and so on.

Is there a way to generate relative paths, without starting "/" like

js/setup.js ?


I use baseUrl in this way:

Yii::app()->baseUrl.’/js/setup.js’, which generates (depending on the project) something like:



/development/js/setup.js (where "development" is the basic folder from the development environment.)

But what I need is this:




so an

Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/setup.js', CClientScript::POS_END);

should generate something like:

<script type="text/javascript" src="js/suchfeld.js"></script>

OR (for development)

<script type="text/javascript" src="development/js/suchfeld.js"></script>

Is there an option to avoid the "/" at the beginning or something like that?

Thank you,


I think you dont need to remove "/" but to change basePath in config/main.php.

As sensorario suggests, I also think you don’t need to remove ‘/’, in fact it’s preferred with ‘/’. But if you like to change request->baseUrl, you can do that in config/main.php in components part:

        'request' => array(

            'baseUrl' => '/base-url',



Thank you, that is, hat I was looking for.

I’ve tried it, but it was not so easy as it looks like first. I hope, I get it work.

Right, I don’t need to remove the “/” at an default environment. But at this special situation, I need an special URL Design, which should not use absolute paths.

where i have change? Getting Error…