2

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.

Francis
  • 1,775
  • 2
  • 12
  • 15
  • Try setting alias using predefined alias. for ex, `Yii::setAlias('@front', '@fronend/path/to/file');` – Insane Skull Jan 05 '16 at 09:36
  • 2
    Possible duplicate of [Yii2 Links between Frontend and Backend (advanced template)](http://stackoverflow.com/questions/26206370/yii2-links-between-frontend-and-backend-advanced-template) – arogachev Jan 05 '16 at 11:21

2 Answers2

3

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.

Ishan Shah
  • 1,665
  • 2
  • 20
  • 42
1

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

Community
  • 1
  • 1
Insane Skull
  • 9,220
  • 9
  • 44
  • 63