from my personal point of view, you are doing it right.
Since you were not too much confident about where to attach events to the EventManager, well, I propose two ways I think, might be cleaner that in the Controller according to your example.
Method #1:
Use CakePHP bootstrap using a Filter which uses the Global Event Manager. This way would be more likely for global events in your app.
Method #2
I think that a more properly event name would be Model.Blog.afterAdd or probably Model.Post.afterAdd instead of current one Controller.Blog.afterAdd.
And neither using the Controller beforeFilter callback to attach it.
Now, how to achieve that?
Well, since you are working with a specific part of your app for handling the event after adding a Post to your Blog (I guess). Why not using the Model beforeSave callback to attach the listener?
Those are just ideas, it's up to you to accept them or reject them :]
Regards.
References:
- Global Event Manager: http://book.cakephp.org/2.0/en/core-libraries/events.html#the-global-event-manager
- Model beforeSave: http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave
-- 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.
No comments:
Post a Comment