简体   繁体   中英

Yii2 show image in backend from frontend - settting alias

In my project I used an image cropper widget. I setup the widget, that it save in frontend/web/upload. But in backend I save the images to frontend too. This is working perfect. Then i want to show the image on the backend, if its exist. And i want to reach the frontend.

Thats why i want to set my own aliases in params-local.php file. But I using vhosts to my webpages and I want to set Aliases to them. In Yii2 documentation i found an article from aliases, but it wont help me. I mean i tried to use but it wont work.

I tried this:

return [
    'aliases' => [
        '@front' => 'http://front.mypage.dev',
        '@back' => 'http://back.mypage.dev',
    ],
];

And I also tried this aswell:

Yii::setAlias('@front', 'http://front.mypage.dev');
Yii::setAlias('@back', 'http://back.mypage.dev');

But when i try to echo Yii::getAlias('@front'); it sais

Invalid Parameter – yii\base\InvalidParamException

Invalid path alias: @front

Maybe someone has a solution for this?

Thanks a lot.

Add in backend/config/params.php like:

return [
    'front' => 'http://front.mypage.dev',
    'back' => 'http://back.mypage.dev',
];

and use it from:

Yii::$app->params['front']
Yii::$app->params['back']

Let me know your thought.

Try this:

Yii::setAlias('@front', 'http://front.mypage.dev');
Yii::setAlias('@back', 'http://back.mypage.dev');

echo  Yii::getAlias('@front');
echo  Yii::getAlias('@back');
echo  Yii::getAlias('@frontend/path/to/file');
echo  Yii::getAlias('@backend/path/to/file');

Yii2 Playground
setting-aliases-in-yii2-within-the-app-config-file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM