image display in Yii2


I am trying to display an image in a view using Yii2 with method Html::img():

the code is simple:

use yii\helpers\Html;

use yii\widgets\ActiveForm;

use yii\helpers\Url;

<?= Html::img('images/test.jpeg');?>

I just added the source.

Do I have to add additional options?


it’s your choice. <?= Html::img(‘images/test.jpeg’, [‘alt’=>‘some’, ‘class’=>‘thing’]);?>

1 Like

With the images, you should reference the folder you are trying to load the image from.

For instance, if the images folder is under frontend/web, the tag should read thus

<?php echo Html::img('@web/images/test.jpeg') ?>

1 Like

so this is for the frontend

<?php echo Html::img('@web/images/test.jpeg') ?>

how to display backend/web/ images on frontend views?

Check this out: