On Tue, Feb 19, 2013 at 3:04 PM, <david.suna@gmail.com> wrote:
> Does anyone have any advice as to how to go about implementing the Event
> Notifier pattern in CakePHP 1.3?
>
> Basically, I want to have email notifications sent out when various events
> occur (adding or deleting instances of specific models). The notifications
> can be sent to different e-mail addresses depending on the model that the
> event occurred on and whether the notification is being sent to the system
> administrator or to a client specific administrator.
>
> To this end I implemented a model called EmailNotification which has the
> client id (0 for system admin), the model to be monitored and the email
> address for the notifications to be sent to.
>
> I would have the models being monitored make a common call with the
> necessary information for the notification email to be sent out. It would
> be the responsibility of this code to look up who the notification should be
> sent to and to send it out.
>
This is similar to something I've been working on, except it involves
image settings. First, I had the data sitting in the various models,
then in the Image model itself. Neither of those is a good solution. I
decided in the end to store everything in Configure. You could do
something like:
Configure::write('Notifications.SomeModel.to', '...');
> My current thought is to have a method on the
> EmailNotificationsController->notify that would be called by the controllers
> of the models being monitored using requestAction.
>
> Alternatively, I could load the EmailNotificationsController using
> App::import and call the method directly from the monitored model's
> controller.
>
> Or is there a better way to implement this?
Better to implement this in a component ... as long as your events
will always be triggered from within a controller. That is, you won't
be calling it in an afterDelete() callback. From the controller:
$this->Notifier->send('ModelName', ...);
Or, maybe pass it a keyed array. In any case, better as a component, imho.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Tuesday, February 19, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment