Yii Framework Forum: App Design: Log + Email On Model Changes - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

App Design: Log + Email On Model Changes Rate Topic: -----

#1 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,688
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 31 October 2012 - 06:27 AM

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?
God is real unless declared as integer
0

#2 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 266
  • Joined: 15-March 09

Posted 31 October 2012 - 08:56 AM

Use events. It's better to have such behavior decoupled from the model's business logic...
Don't like ads in my sig...
0

#3 User is offline   yiqing95 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 586
  • Joined: 27-December 10
  • Location:china

Posted 31 October 2012 - 09:01 AM

if i were you i will prefer this :
auditTrail + cron job :lol:
0

#4 User is offline   ecpasar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 31-October 12

Posted 31 October 2012 - 08:00 PM

The best way is to change the model.
0

#5 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 22-September 12

Posted 23 April 2013 - 04:14 PM

View PostORey, on 31 October 2012 - 06:27 AM, said:

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?


ORey,

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users