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


Is there a more elegant solution?

baseUrl is the base-path of your URLs, for example on this site.

You’re probably looking for filesystem paths: use aliases ( (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 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 is hosted at (‘protected’ by default)