zxbodya / yii2-gallery-manager

93 stars 61 forks source link

Calling getUrl() function from frontend returns NULL (in advanced app) #16

Open amismailz opened 9 years ago

amismailz commented 9 years ago

'directory' => Yii::getAlias('@webroot') . '/backend/media/transport/gallery', 'url' => Yii::getAlias('@web') . '/backend/media/transport/gallery',

The previous two properties read paths differently in backend & frontend. My model in backend, so getUrl() returns true path in backend, but in frontend not working. How can I fix this, Thanks.

zxbodya commented 9 years ago

getUrl() method will return null, in case when it can not find image file.

To use the same model for both apps (frontend and backend), you need two things:

  1. directory should point to the same folder in both apps
  2. url should correctly specify url prefix for images in that folder in both apps

In your case Yii::getAlias('@webroot') and Yii::getAlias('@web') will point to differect places in different apps.


I am using following configuration for this case:

  1. I have separate folder for all user uploaded files, and it is shared between both apps: Yii::setAlias('contentRoot', dirname(dirname(__DIR__)) . '/contentRoot'); in common/config/bootstrap.php
  2. Following config in gallery behaviour:
    • 'directory' => Yii::getAlias('@contentRoot') . '/images/product/gallery',
    • 'url' => Yii::getAlias('@web') . '/images/product/gallery',
  3. And aliases to images folder from contentRoot folder, for both apps in nginx config:
    • location /images/ { root /work/contentRoot; }
amismailz commented 9 years ago

Oh Dear, i think that life is more simpler than this! If this is the best solution, my issue now is that I'm using "apache" not "nginx".

zxbodya commented 9 years ago

You can use mod_alias in apache, or you can just create symlink.

Or alternatively you can replace Yii::getAlias('@web') with absolute url.