Open amismailz opened 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:
directory
should point to the same folder in both appsurl
should correctly specify url prefix for images in that folder in both appsIn 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:
Yii::setAlias('contentRoot', dirname(dirname(__DIR__)) . '/contentRoot');
in common/config/bootstrap.php
'directory' => Yii::getAlias('@contentRoot') . '/images/product/gallery',
'url' => Yii::getAlias('@web') . '/images/product/gallery',
location /images/ { root /work/contentRoot; }
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".
You can use mod_alias
in apache, or you can just create symlink.
Or alternatively you can replace Yii::getAlias('@web')
with absolute url.
'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.