How to raise CComponent event in Yii
- by srigi
Let's assume I have Component (say Graph like Yahoo Finance) rendered on the page. Component view template contains bunch of a_hrefs which I wanto to switch period in graph. I created Event and Event handler in Component. I have two questions:
How to raise event on Graph Component via those a_hrefs (should they be part of Graph?)?
How to redraw Graph without loosing curent page context (section, filter - specified as $_GET values)?
My Graph Component look like this:
Yii::import('zii.widgets.CPortlet');
class Graph extends CPortlet
{
private $_period;
/* ********************** *
* COMPONENT PROPERTIES *
* ********************** */
public function getPeriod()
{
return $this-_period;
}
public function setPeriod($period)
{
$this-_period = $period;
}
/* ********************** *
* GENERIC *
* ********************** */
public function init()
{
parent::init();
// assign event handlers
$this-onPeriodChange = array($this, 'handlePeriodChange');
}
protected function renderContent()
{
$this-render('graph');
}
/* ********************** *
* EVENTS *
* ********************** */
public function onPeriodChange($event)
{
$this-raiseEvent('onPeriodChange', $event);
}
/* ********************** *
* EVENT HANDLERS *
* ********************** */
public function handlePeriodChange($event)
{
// CODE
}
}