Lenny Carmi
Lenny Carmi

Reputation: 783

How can I concatenate the following in Yii2?

I have the following on my view file which I need to display as an image.

<img src="<?php echo PATH; ?>web/images/ad_image/<?php echo $ads['ads_id']; ?>.png " width="790" height="100" />

My PATH is Yii::$app->request->baseUrl. This does not work so I thought of using Yii alias @web and Html helpers like this:

    echo Html::img('@web/images/ad_image'.$ads['ads_id'].'.png', ['width' => 790, 'height' => 100]); ?>

That does not work too so I tried this and my image still does not show:

    $bf_ad = $ads['ads_id'];
    echo Html::img('@web/images/ad_image'.$bf_ad.'.png', ['width' => 790, 'height' => 100]);

What is the way to display this when I am loading from an array $ads which I get by foreach (Yii::$app->params['ads_details'] as $ads) {?

Upvotes: 1

Views: 365

Answers (2)

Chinmay Waghmare
Chinmay Waghmare

Reputation: 5456

Try this:

echo Html::img(Yii::getAlias('@web').'/images/ad_image/'.$ads['ads_id'].'.png', ['width' => 790, 'height' => 100]);

Upvotes: 2

GAMITG
GAMITG

Reputation: 3818

Try

$bf_ad = $ads['ads_id'];
echo Html::img(Yii::getAlias('@web').'/images/as_image/'.$bf_ad.'.png', ['width' => 790, 'height' => 100]);

Upvotes: 2

Related Questions