how to call a constant value throughout controller

Hello,

In root index.php:

"Yii::createWebApplication($config);

define(‘UPLOAD_DIRECT’,Yii::app()->baseUrl.’/images/upload_folder/’);

Yii::app()->run();"

In controller I am calling this constant while uploading image under create function, like

$uploadedFile->saveAs(UPLOAD_DIRECT.$fileName);

while uploading I am getting error as " Use of undefined constant UPLOAD_DIRECT - assumed ‘UPLOAD_DIRECT’ ".

I am new to yii framework can anyone help me to sort out this.

Thanks waahi. :blink:

Hi Sally,

You can try to create a Helper class and declare a constant:


class Helper {


const UPLOAD_DIRECT = Yii::app()->baseUrl.'/images/upload_folder';


}

In your controller:




$uploadedFile->saveAs(Helper::UPLOAD_DIRECT.$fileName);

Thanku for ur reply,

where do I create helper class?

You can create it inside model folder.