I must be looking at this wrong, but how do I setup complex variables inside a CApplicationComponent?
I’m setting up a quick group of Global “constants”
class Globals extends CApplicationComponent
{
public $currentFY;
public $previousFY;
public function init()
{
$now = date('Y-m-d');
$currentFY=array();
$previousFY=array();
$march31 = date('Y-m-d', mktime(0,0,0, 3, 31, date('y')));
if ($now <= $march31)
{
$currentFY['start'] = date('Y-m-d', mktime(0,0,0,4,1,date('y')-1));
$currentFY['end'] = $now;
$previousFY['start'] = date('Y-m-d', mktime(0,0,0,4,1,date('y')-2));
$previousFY['end'] = date('Y-m-d', mktime(0,0,0, 3, 31, date('y')-1));
} else {
$currentFY['start'] = date('Y-m-d', mktime(0,0,0,4,1,date('y')));
$currentFY['end'] = $now;
$previousFY['start'] = date('Y-m-d', mktime(0,0,0,4,1,date('y')-1));
$previousFY['end'] = date('Y-m-d', mktime(0,0,0, 3, 31, date('y')));
}
parent::init();
}
}
When I go to access Yii::app()->Globals->currentFiscalYear[‘start’], it’s null.
I stepped through and init is called and the values are set, but once I leave the function, it’s all lost.
I assume this is a scoping issue, but how would I go about doing this if init doesn’t cut it?