Yii Framework Forum: CModel event onAfterConstruct doesn't fire after model creation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CModel event onAfterConstruct doesn't fire after model creation Yii 1.1.8 affects: classes that extend from CActiveRecord Rate Topic: -----

#1 User is offline   Kiriakos Kappa Krastillis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 06-June 11
  • Location:Greece

Posted 29 February 2012 - 05:35 AM

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'.

This post has been edited by Kiriakos Kappa Krastillis: 29 February 2012 - 05:36 AM

I like software development.
KINDstudios.gr
0

#2 User is offline   mariusn 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 16-March 12

Posted 31 August 2012 - 03:38 AM

View PostKiriakos Kappa Krastillis, on 29 February 2012 - 05:35 AM, said:

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


@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.
0

#3 User is offline   glyph 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 20-April 12
  • Location:Michigan, USA

Posted 06 February 2013 - 11:40 AM

I ran into this problem once when I accidentally declared behaviors in a controller instead of a model.
-------------------------------------------------
Glyph Imaging and Data Services
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users