Setting Component Defaults Classwide

I have a question regarding this http://stuff.cebe.cc…aults-classwide

Could I attach a behavior to all my models like so?





\Yii::$objectConfig = [

    'yii\db\ActiveRecord' => [

        'behaviors' => [

            'class' => 'MyBehavior',

        ],

    ],

];

Even if they are descendants of ActiveRecord?

As per my understanding yes, you could for the Yii classes (almost all of which extend from the Object class). Its the way the Yii Object calls Yii::configure in its construct.

It will only fail if you have overridden the init() or similar method in your extended class to override the default class config.

I have seen most Yii Core Classes carefully developed - so that properties/variables are not overridden in a class method/function - for this global configuration to be feasible. You can cross check this for AR class as well.