I'm trying to set alias path in Yii to my file upload directory in
testweb
- ...
- protected
- ...
- myupload
So I put like this in protected/config/main.php:
Yii::setPathOfAlias('upload_dir', Yii::getPathOfAlias('webroot') . '/myupload');
But then when I echo the alias, I only get '/myupload'
echo Yii::getPathOfAlias('upload_dir'); //only returns /myupload
You can't call getPathOfAlias() inside your main.php configuration file, because path aliases are created in the constructor of CApplication. But the constructor wasn't called yet at the point when main.php is included.
The right way to configure path aliases, is to use the aliases property in your main.php. In your case you could do:
return array(
'aliases' => array(
'upload_dir' => 'webroot.myupload',
),
...
Also note, that you can (and should) make use of the dot notation for aliases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With