Reputation: 95
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!!!
Upvotes: 1
Views: 3407
Reputation: 133360
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']) ?>
Upvotes: 1
Reputation: 5721
Try This:
<img src="<?=Yii::$app->request->baseUrl?>/image/class.jpg">
Yii::$app->request->baseUrl : It returns path from root to web
OR you can use
<img src="<?=Yii::getAlias('@web'); ?>/image/class.jpg">
Upvotes: 1