How can I define an UPLOAD_DIR constant (or equivalent) so that I can use it everywhere?
I tried this as an application configuration parameter
'params'=>array(
'upload_dir'=>Yii::app()->baseUrl . '/images/uploads/',
),
but Yii::app()->baseUrl cannott be used inside the config file.
You can do this inside
index.php, after the call toYii::createApplicationand beforeYii::app()->run():You would then use it just like any other PHP constant, e.g.
echo UPLOAD_DIR.Edit: When I said after
createApplicationand beforerun, I meant exactly that (also, not that there is both acreateWebApplicationand acreateApplication, which is a more generalized version of the former).So if you currently have
you have to split it into
Another option would be to just add another property to your application class. For example, if you have a
class MyApplicationinside yourprotected/componentsdirectory then you can simply do this:You would then access this as
Yii::app()->uploadDir.