CModel event onAfterConstruct doesn't fire after model creation

As discussed - without resolution - in the general discusion forum I am experiencing trouble with this event.

The problem affects module models that extend from a modified CActiveRecord class (the getDBConnection method is overwritten, nothing else).

The problem after looking stepping through execution with the debugger is that


$model->_e['onafterconstruct'] 

is not defined

while the model class definitely states:




public function  onAfterConstruct($event) {

            die('onAfterConstruct');

            parent::onAfterConstruct($event);

        }



I am not sure if this is a bug or if I am missing something key here. I left the thread in the general discussion forum for five days now and no significant insights have been offered.

I have given up on this and worked around the issue (I wanted to use the event for default initialization of the model) and just use an init call on each `new model’.

@Kiriakos:

Did you ever find a solution for this? I think being able to add event listeners globally would really enhance the usefulness of events.

Have you seen this post ? Events Observer

It does the job nicely.

If you look through the comments you’ll see that there could be another approach using behaviours which is more efficient - but it would rely on this event.

Debugging it should be possible - perhaps by stepping through an unextended instance of ActiveRecord.

I ran into this problem once when I accidentally declared behaviors in a controller instead of a model.