Reputation: 190
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
Upvotes: 3
Views: 7959
Reputation: 7627
use something like this
Yii::setPathOfAlias('upload_dir', dirname(__FILE__) . DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."myupload");
Upvotes: 0
Reputation: 8587
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.
Upvotes: 5