C.Roshan C.Roshan - 2 months ago 12
HTML Question

How to set a image path in yii framework?

Here is my coad.

<?=Html::img('file_path',['alt' => 'class room'])?>


my image real path is
web/image/class.jpg
. How to set the path in file_path.

Anybody knows how to solve my problem?

Thanks in advance!!!

Answer

you can use Yii::$app->request->baseUrl;

<?=Html::img( Yii::$app->request->baseUrl;  .  'file_path',['alt' => 'class room'])?>

could be you need /image/

<?=Html::img(Yii::$app->request->baseUrl;  . '/image/' .  'file_path',['alt' => 'class room'])?>

see this for more http://www.yiiframework.com/doc-2.0/guide-helper-url.html

You can try with @web to ... but instead of 'file_path' .. you probably need a $model->attribute refer

<?= Html::img('@web/image/' . $model->file_path , ['alt' => 'class room']) ?>