Hi, I need to have a param that holds the path to the images.
It needs to be relative to Yii::getPathOfAlias(‘webroot’) since the app is tested in and deployed to different environments.
But can’t use Yii::getPathOfAlias(‘webroot’) inside config/main.php, so this is the way I found to make it work, although it’s a little dirty as I see it.
I added this to the end of the entry script index.php
Maybe a parameter is not the best place to store a dynamic path. I usually only save user defined config options there. Since you now kind of hard code the path in your index.php it’s not really configurable in the end. How about using a custom alias instead?
// config/main.php:
'params'=>array(
'imageAlias' => 'webroot.images',
...
// index.php
$app=Yii::createWebApplication($config);
Yii::setPathOfAlias('images', Yii::getPathOfAlias($config['params']['imageAlias']));
$app->run();
// Somewhere:
$imageFolder=Yii::getPathOfAlias('images'); // not much longer than accessing a parameter