tags:

views:

66

answers:

1

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:

  1. How to raise event on Graph Component via those a_hrefs (should they be part of Graph?)?
  2. 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
 }
}
A: 

You can raise it this way:

$graph = new Graph(); $event = new CEvent($graph); $graph->onPeriodChange($event);

To redraw graph you should collect params passed via $_GET and use them again when forming url for refresh().

Sam Dark