Yii Framework Forum: Event onAfterConstruct doesn't fire. - Yii Framework Forum

Jump to content

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

Event onAfterConstruct doesn't fire. I can't seem to be able to get an AR event to fire Rate Topic: -----

#1 User is offline   Kiriakos Kappa Krastillis 

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

Posted 24 February 2012 - 07:58 AM

So I am developing a module atm that has it's own AR objects stored to an sqlite db.

the base class is just a stub that looks like this:
class EBActiveRecord extends CActiveRecord {
       public function getDbConnection()
        {
            $db = Yii::app()->controller->module->db;
            return Yii::createComponent($db);
        }

}


and all models of the module extend EBActiveRecord.

Now, I am getting all events fine except onAfterConstruct.

what do I need to do?


NOTE: I am trying to trigger it via $t = new BTransaction(); so the new keyword should trigger the event...

EDIT: this is for Yii 1.1.8 but judging from the changelogs this shouldn't be an issue.
I like software development.
KINDstudios.gr
0

#2 User is offline   Vitalets 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 16-December 11
  • Location:Moscow / Russia

Posted 24 February 2012 - 01:17 PM

Hi Kiriakos

1. may be Yii::app()->controller->module->db is already instanced object? See in debugger what is inside $db.
2. how youe check that onAfterConstruct is not raised?
have a look on my extensions:
EColumns - show/hide and reorder columns in gridview
GroupGridView - merge cells and make group rows in gridview
SelGridView - keep selection in gridview
0

#3 User is offline   Kiriakos Kappa Krastillis 

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

Posted 24 February 2012 - 06:26 PM

Well, I have inserted a die() statement at the top of the onAfterConstruct function in the AR model's class.
Normally that should kill the application and output the debug message of the die statement.

I don't think that db has anything to do with it, I will do a cross check in the morning and come back to
that.
I like software development.
KINDstudios.gr
0

#4 User is offline   Kiriakos Kappa Krastillis 

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

Posted 27 February 2012 - 02:35 AM

Well, I banged my head on this for a part of the weekend but couldn't find a solution.
I'm forced to work around this issue which turns out to be quite ugly.

If anybody has an idea why the event is not firing or how I could make it fire please share your thoughts.
I like software development.
KINDstudios.gr
0

#5 User is offline   Vitalets 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 16-December 11
  • Location:Moscow / Russia

Posted 27 February 2012 - 03:25 AM

hi Kiriakos

are you using debugger?

You should start from line of your code where new operator creates EBActiveRecord object. And then step in __contruct() function till call of $this->afterConstruct();
have a look on my extensions:
EColumns - show/hide and reorder columns in gridview
GroupGridView - merge cells and make group rows in gridview
SelGridView - keep selection in gridview
0

#6 User is offline   Kiriakos Kappa Krastillis 

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

Posted 28 February 2012 - 07:44 AM

I did that. the hasEventHandler function returns false. Apparently $model->_e['onafterconstruct'] is not set.

Why not? I'm currently digging into that but am a bit clueless as far as core events goes...
Do I need to attach this one somehow?
I like software development.
KINDstudios.gr
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