Global behaviour configuration

Is it possible to attach default behaviors in application config?

Maybe I am not clear with what I ask…

I have several models and several behavior components. I can attach a behavior directly to model instance. But I want it to be attached automatically upon model construction. I guess it’s obvious that such possibility should exist in application configuration.

Maybe someone knows how to make it right.

Yes it is possible, just define




'onBeginRequest' => 'callback'



in your config. API contains all events that components support to attach handlers to.

As far as I understand you are suggesting to attach event handlers to application events. That’s not what I need. I need to attach behavior (not just event handlers) to specific model. But I don’t want to do it in either model’s or controller’s code. I want it to be attached automatically.

I see. Application configuration are processed far before your models get loaded and used.

You may want to extend CActiveRecord::behaviors() if that fits your needs. If you want to attach behaviors to more models, you should create an abstract subclass of CActiveRecord.