C.Roshan C.Roshan - 1 year ago 77
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
. How to set the path in file_path.

Anybody knows how to solve my problem?

Thanks in advance!!!

Answer Source

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']) ?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download