[ASK] ImageUrl like hostInfo or baseUrl

<?php echo Yii::app()->request->hostInfo; ?>

give result : http://hostname/

how to give another result like this :

http://images.hostname/ or http://imageshost/

Read about this.

Your question is hard to understand. What do you try to do?

Yii::app()->request->hostInfo; will per definition always give you the name of the host you sent the request to. If you don’t want that, why do you use it then?

i’m so sorry if my question is hard to understand.

for page url like http://hostname/site/about

i can use <?php echo Yii::app()->request->hostInfo; ?>site/about

so now, i want to create a shortcut for image url

for example if my image link is http://hostname/images/sample.jpg

if i use <?php echo Yii::app()->request->hostInfo; ?>images/sample.jpg

it’s to long…

my question is how to create image url like this:

<?php echo Yii::app()->request->imageUrl; ?>sample.jpg

where imageUrl will give path like http://hostname/image/


You should not create your URLs like this. Instead do this

for actions:

Yii::app()->createUrl('site/about');   // works everywhere

$this->createUrl('site/about');  // works in view files

for images and other static files i recommend to use the bu() helper, described in this wiki article:


So you would write:

<?php echo bu('images/sample.jpg'); ?>

You do not need the hostinfo part for all your images, css, etc. Just make sure, the baseUrl is prepended correctly with bu().

thanks mike…

it’s what i want.