How to raise CComponent event in Yii
Posted
by srigi
on Stack Overflow
See other posts from Stack Overflow
or by srigi
Published on 2010-06-16T08:14:21Z
Indexed on
2010/06/16
8:22 UTC
Read the original article
Hit count: 217
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 } }
© Stack Overflow or respective owner