Php 如何在Yii中引发CComponent事件
假设我在页面上呈现了组件(比如像Yahoo Finance这样的图形)。组件视图模板包含一堆我想在图中切换周期的HREF。我在组件中创建了事件和事件处理程序。我有两个问题:Php 如何在Yii中引发CComponent事件,php,events,yii,Php,Events,Yii,假设我在页面上呈现了组件(比如像Yahoo Finance这样的图形)。组件视图模板包含一堆我想在图中切换周期的HREF。我在组件中创建了事件和事件处理程序。我有两个问题: 如何通过这些a_HREF在图形组件上引发事件(它们应该是图形的一部分吗?) 如何在不丢失当前页面上下文的情况下重新绘制图形(节,过滤器-指定为$\u GET值) 我的图形组件如下所示: Yii::import('zii.widgets.CPortlet'); class Graph extends CPortlet {
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
}
}
你可以这样提高它: $graph=新图形(); $event=新的CEvent($graph); $graph->onPeriodChange($event)
若要重新绘制图形,您应该收集通过$\u GET传递的参数,并在形成refresh()的url时再次使用它们。我认为如果存在事件处理程序,您可以调用,所以调用事件处理程序
public function setPeriod($period)
{
if($this->hasEventHandler('onPeriodChange'))
$this->onPeriodChange($this);
$this->_period = $period;
}