baseUrl in main.php

Suppose I needed to supply Yii::app()->baseUrl for configuration of some component. How would I do it without hard-coding?

I guess I could just use


str_replace($_SERVER['DOCUMENT_ROOT'],'',realpath('.'));

Is there a more elegant solution?

baseUrl is the base-path of your URLs, for example http://www.yiiframework.com/ on this site.

You’re probably looking for filesystem paths: use aliases (http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace) (and maybe call Yii::getPathOfAlias)

@M-J: Could you give a better example? Why wouldnt u use the Yii::app()->baseUrl call within that component?

@Javache: Don’t mix up baseUrl and basePath. Assuming that http://www.example.com/ is based on Yii, baseUrl would return ‘/’ (relative URL) and basePath would return whatever directory the app is located at in the local directory which example.com is hosted at (‘protected’ by default)