Answer the question
In order to leave comments, you need to log in
What needs to be written so that there is a correct URL for frontend and backend in yii2?
There is a site on an openserver and the following domains are registered to it:
Domain name: localhost. Domain folder: \localhost\frontend\web
Domain name: admin.localhost. Domain folder: \localhost\backend\web
Images are saved and displayed in the admin panel in the folder backend/web/upload/images
Here is an example of how I display an image in the admin panel:
$dir = '/upload/images/preview-' . $model->img;
return Html::img(Yii::$app->urlManager->createUrl($dir));
Answer the question
In order to leave comments, you need to log in
Good afternoon.
You can do this:
In common/config/main.php
$baseUrlFrontend = str_replace('backend/web', '', (new Request)->getBaseUrl());
return [
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'urlManagerFrontend' => [
'class' => 'yii\web\UrlManager',
'baseUrl' => $baseUrlFrontend,
'enablePrettyUrl' => true,
'showScriptName' => false,
]
]
]
$img = (Yii::$app->urlManagerFrontend->createUrl( $model->images[0]['path'] . DIRECTORY_SEPARATOR . $model->images[0]['title']));
echo Html::img($img);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question