Event onAfterConstruct doesn't fire.

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.

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?

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


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.

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();

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?