Events Library (v0.5) |
[eluser]Milos Dakic[/eluser]
Well this is my first contribution to the CodeIgniter Community, so please take it easy on me =] I’ve been working on an events library over the last week or so and I would like to contribute it to the community. Introduction Events is a library which can handle events / actions that occur within an application or site, that can be extracted from the controller/model. Events can work with a standard CodeIgniter install as well as with the Modular Extension (ME) library. Documentation Download v0.5 (beta) I would like some community feedback as to what you think about the library and what can/needs to be improved. Please keep all comments within this thread as I will use it as the main feedback source. Enjoy!
[eluser]Jay Logan[/eluser]
I don't know if I entirely understand what this does. I'm fairly new to programming so bare with me. Is this a library that can basically store actions that a user does? I'm looking for a way to track user activity on my site and produce a log for my admins that shows info like: 02/19/2008 4:00PM - {{username}} has added John Doe to his list of friends. Almost like a Facebook displays user activity. Would your library work for me?
[eluser]Milos Dakic[/eluser]
Well it could. What you would do is setup many events that only have a single callback. Code: $this->events->register(array('on_friends_add','on_friends_remove','on_friends_modify'),'on_friends_log'); So what you would do in your controllers and models is call any of these events depending on the actions and just pass the data through. The function 'on_friends_log' would take care of the logging part for you. It simply means that multiple events will have a single outcome or action. Let me know how you go.
[eluser]Iverson[/eluser]
Thanks for the contribution but I don't really understand how these events work. What's the difference between your example code and my example below. Maybe I'm missing something? Code: function add($email)
[eluser]Milos Dakic[/eluser]
It's the separation factor. Imagine you had to use the same function over and over in a number of controllers. Its just an easier way of moving things out of the MVC structure to better allow you to manage "events" or "actions". I understand what you are trying to say, but imagine you had to call 3-4 different functions when a user subscribes. 1. Send email to admin. 2. Send the user an email that they have joined. 3. Add a small alert to your admin panel telling you someone had join (example, you most likely wouldn't use it for this). I currently work on a massive e-commerce / CRM / CSM solution which requires you to send things, write PDF's, write HTML files etc. Its very hard to organize things when they are within your controller. You have to remember each and every controller that you put an event/action into. This way you can go to one central location and adjust or change an event that is being called.
[eluser]xwero[/eluser]
For people who can't see the use, i advise to check out the hooks documentation in the user guide. The feature this library has over the CI hooks class is the possibility to add dynamic data. In another thread i have taken your idea to the hooks class.
[eluser]Milos Dakic[/eluser]
This was just my implementation of the hooks class. I didn't want to extend the core but rather add more to it. Its a very simple class that helps me out very much. I see the hooks class as extending the core of the framework rather then controllers or modules.
[eluser]Colin Williams[/eluser]
Good stuff. But I think you should rid the idea of registering actions and just use naming conventions And those who don't get it should read up on a few buzzwords like 'abstract-oriented programming' and 'decorator pattern' Google it
[eluser]garymardell[/eluser]
I made one change to the library and that was public function trigger($event, $params = null, $result = null) I set params to be null otherwise, it makes it easier if i dont want to pass any params and its neater than having $this->events->trigger('on_events_page', ''); or $this->events->trigger('on_events_page', null); I can just call $this->events->trigger('on_events_page');
[eluser]Milos Dakic[/eluser]
@gazza; I see what you mean. I'll make the change when I get a chance. @Colin; I was looking into auto loading the handlers, that way you can just set it up and your done. |
Welcome Guest, Not a member yet? Register Sign In |