App Design: Log + Email On Model Changes

Hi guys.

Let’s suppose I want to log every model change (create, update, delete).

As for me, the most convenient place for this is the model itself (attached behavior, for example).

But the time passes by, and now I want to send a notification email to project’s team (“Hey, look, something has changed!”).

Seems like putting mail sender into model isn’t good decision (model sending emails? wtf?), especially if sending email involves template rendering (everybody loves pretty-looking emails).

So what do you think? how this should be designed?

Use events. It’s better to have such behavior decoupled from the model’s business logic…

if i were you i will prefer this :

auditTrail + cron job :lol:

The best way is to change the model.


Did you ever sort this problem out? I am looking at a situation where information is being brought into the db outside of Yii and I need to send emails based on certain data conditions.

Thought I could trigger an event on New Record insert…but calling the controller from the model seems backwards.

Likewise, sending email from the model seems a bit strange.