[SOLVED] migrating yii to a subdirectory maintaining links

Hi all,

I’ve created a web app in yii, it’s located in the webroot of my server (i.e. www.mydomain.com/index.php) and it works perfectly as is. However I’m moving it to a new server and it’s going to be located in a subdirectory of the root folder, i.e. mydomain.com/yii/index.php.

The problem is I’ve set up all my links/images etc like so:

[PHP]echo CHtml::image(’/images/myImage.jpg’,‘alt text’);[/PHP]

In the above example the image is still pointing to www.mydomain.com/images/myImage.jpg, however because the app is now in a subdirectory, the actual url of the image is www.mydomain.com/yii/images/myImage.jpg.

Is there a better way to write code to allow for this kind of situation, or a way to prepend all links with the base root of the actual app?

I thought of adding a param to the main config and pre-pending that value to the CHtml::link() / CHtml::image() methods, but that’s not the best way of doing things as I don’t want to play with the framework files if possible and, more importantly, it just doesn’t seem “right”, as there may be more urls that I’ve programmed in that are pointing in the same way, e.g. CController::redirect() I think is another example?


Yup, you can use

echo CHtml::image(Yii::app()->baseUrl . '/images/myImage.jpg','alt text');

of course! thanks :)