I have img tag in my view file like the below.
<img src="<?php echo Yii::app()->baseUrl.'/img/test.jpg'; ?>" />
But, it doesn't show the image.
I have "img" folder on the same directory where index.php
(front controller)exists.
What's wrong!?
Anybody knows how to solve my problem?
Thanks in advance!!!
+++Added 1+++
I'm developing in local environment.
+++Added 2+++
Very weird thing is happening.
When I access the one specific image by typing the path to the image on browser, the requested image is displayed.
http://localhostname/img/sidebar.gif
But when I access the other images in the same img foloder, I get "Forbidden" error.
Also, when I type the below in my view, it shows the image.
<img src="<?php echo Yii::app()->baseUrl.'/img/sidebar.jpg'; ?>" />
But, when I type the path to the other images that exists in the same img directory, it doesn't show any images.
Instead of Yii::app()->baseUrl
Try this: Yii::app()->getBaseUrl(true)
By default, baseUrl returns relative URL.
<img src="<?= Yii::app()->getBaseUrl(true) ?>/img/sidebar.jpg" />
If images not show, the debug browser have error 404. See there. You will see full url that should get. It url not the one you expect - "<?php echo Yii::app()->baseUrl.'/img/test.jpg'; ?>"
. You should edit you code in conformity with this error.