Handling An Event Raised In A Model

I built a plugin architecture where the plugins react to some events raised. It already works fine as long as I raise events in views or controllers. But now I want to raise an event in a model class and get the following problem:

I want to raise an event „doSomeMoreModifications($event)“ inside oft the model’s afterFind()-Method in order to allow some of my plugins to modify the found model’s attributes. (e.g. change an attribute’s value only if this plugin is installed)

I have a plugin class, in which I want to attach the corresponding eventHandler. But this does not work. Any ideas what I am doing wrong?

What I have is:




class MyOriginalClass extends CActiveRecord { 

    ...

    public function afterFind() {

        parent::afterFind();

        …

        $this->raiseEvent('onAfterFindModify', new CEvent($this));

    }

}


class MyPlugin extends CApplicationComponent {

    public function init() {

        parent::init();

        MyOriginalClass::model()->attachEventHandler( 'onAfterFindModify', array($this, 'doTheModification'));

    }

    public function doTheModification($event) { 

        …

    }

}



I finally found my solution thanks to these extensions:

event-interceptor

static-events