Using events in Yii

I was looking at the event handling in Yii and I am not sure if I do understand it correctly. Say I would like to always do something before an activeRecord is saved.

Usually I would override beforeSave() (also calling the parent implementation).

But it seems like I could also attach an event to my activeRecord class like this:

$myActiveRecord->onBeforeSave=$callback;

  1. Are there any tutorials or good examples about this? When should I use events?

  2. The onBeforeSave() method should not be overriden, right?

The design of this event is meant to be used by AR behaviors. It is valid that you can attach an event to the onBeforeSave event. However, this won't bring you much convenience because it only attaches the handler to the specific AR object. Normally, you don't need to override onBeforeSave() method. You should override beforeSave(), instead. Make sure you call parent::beforeSave().

Thanx qiang, I think I got it.