讓我們假設我在頁面上呈現組件(比如Yahoo Finance等Graph)。組件視圖模板包含一堆我想要在圖形中切換週期的a_hrefs。我在Component中創建了事件和事件處理程序。我有兩個問題:如何提高Yii中的CComponent事件
- 如何通過那些a_hrefs引發圖組件事件(它們應該是Graph的一部分嗎?)?
- 如何重繪圖而不丟失頁面上下文(section,filter - 指定爲$ _GET值)?
我的圖形組件是這樣的:
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
}
}