Mohammad
Mohammad

Reputation: 3547

how to access frontend files from backend

I want to print an image in a backend view. the image exists in frontend, so I used the alias to print it like:

<img src="<?= Yii::getAlias('@frontendWeb') . "/uploads/clients/{$model->img}"; ?>"/>

where the @frontendWeb alias is defined in common\config\bootstrap as:

Yii::setAlias('@frontendWeb', dirname(dirname(__DIR__)) . '/frontend/web');

the image URL is true, and I can see it if I open its URL directly from the browser, but unfortunately it didn't shown in the view file.

Upvotes: 1

Views: 1068

Answers (2)

user7699448
user7699448

Reputation:

try this

<img src="<?= Yii::getAlias('@frontendWeb') . "/uploads/clients/" . $model->img . ".jpg" ?>" class="photos"/>

Upvotes: 1

user2831723
user2831723

Reputation: 892

Why not use direct links, as the images in front-end are accessible publicly anyways

<img src="<?= Url::base(true) ?>"/uploads/clients/"<?= {$model->img} ?>"/>

Upvotes: 1

Related Questions