Hello.
In our system we have “abstract class Document extends ActiveRecord” and we need all child classes to react on EVENT_AFTER_UPDATE.
This is why I created a behavior that contains the afterUpdateHandler() function.
Now I need to use DI to inject this behavior to the abstract class (so all children can use it) and attach its function afterUpdateHandler() to the AR event EVENT_AFTER_UPDATE
Important is to know this all is in a module. So I added method init() to the file Module.php, but the behavior is not injected. I probably have something wrong.
I am doing it like this:
Yii::$container->set(Document::class, [
'as documentUpdateBehavior' => DocumentUpdateBehavior::class,
// 'on EVENT_AFTER_UPDATE' => ['$this', 'afterUpdateHandler'],
]);
The 2nd line in my snippet is commented out, because I am not sure how to write it. I will be glad for guidance!
PS: It might also be important to know that model Document already has some behaviors in its method behaviors()