'Hook into User Save from a separate module

I'd like to use modules to separate code in a large monolithic Yii app. Let's say there is a core module which has a User model, and I'm creating a new audit module which tracks user updates.

The audit module has an AuditLog model which stores information about changes to the User model.

If I wasn't trying to keep the audit context separate, I could just add the audit logic to User->afterSave().

What is the most idiomatic way in Yii to react to a user being saved, without adding Audit specific logic to the User model?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source