Events How To?

dear friends pls help me to create and and attach events to the event handlers? because I wanted to implememt in my newly created class. thank you.

Does your class override CComponent*? Can you post your code so we can assist?

Matt

no I am not started yet. but could you help me where do I extend my class(I want to create class with basic image functionalities) and how to create events





class ImageResizer extends CComponent // OR CApplicationComponent

{

	public function onResize($event)

	{

		$this->raiseEvent('onResize', $event);

	}

	

	public function resize($path)

	{

		// magic here


		$this->onResize(new CEvent($this));

	}

}


// Main config

'components'=>array(

	'resizer'=>array('class'=>'ImageResizer'),

	 ...

	)


// Attach an event handler before calling the resize method

Yii::app()->resizer->onResize = array(new HandlerClass, 'handlerMethodName');


public function actionResize()

{

	...

	// Call your component to resize

	Yii::app()->resizer->resize($path);

}



/* Moved to General Discussion */

everything ok but why we use this ?Yii:: app ()-> resizer-> onResize = array ( new HandlerClass , ‘handlerMethodName’ );

Before any application code that needs to capture the event. Common places include

  • [size=2]a module’s init() method[/size]
  • [size=2]a controller’s beforeAction() method[/size]
  • [size=2]or in a controller’s inline action[/size]



public function actionResize()

{

    Yii::app()->resizer->onResize = array($this, 'resizeEvent');

    

    $path = ....;

    Yii::app()->resizer->resize($path);

}


public function resizeEvent($event)

{

    // Resize complete

}