M
M
Maybe_V2016-06-13 12:43:44
Yii
Maybe_V, 2016-06-13 12:43:44

How to access frontend files in backend?

There was a need to save pictures in /frontend/web/uploads/team/(advanced template).
Now we need to display these pictures backendin some views.
I write the output of the image like this:

echo BaseHtml::img('@frontend/web/uploads/team/'. $model->image, ['width' => '150px','height' => '150px']);

But as a result I get just an area in which nothing is displayed:
b2b7dd8ee4484b31b4dc046451e06cf1.png
But if you make a folder simply in the root of the project or in /backend/web/- everything works fine!
Made an alias to the folder with pictures:
Yii::setAlias('@imageTeam', '@frontend/web/uploads/team/');

It still doesn't show the picture!
How to get files from frontendto backend?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
polar-bear, 2016-06-13
@prokopov-vi

You can do this:

Yii::setAlias('@frontendHost', 'http://example.com');
echo Html::img('@frontendHost/uploads/team/'. $model->image, ['width' => '150px','height' => '150px']);

G
George, 2016-06-13
@gogametreveli

There are several ways to solve this problem
1. Make a SymLink to /frontend/web/uploads/ in (if you have Linux) to the folder with images
(ln -s path-to /frontend/web/uploads/ path-to/backend/web /uploads/)
2. When uploading images /frontend/web/uploads/ duplicate /backend/web/uploads/
3. Write a PHP class that renders images

D
dev400, 2016-06-13
@dev400

common?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question