Dan Horrigan (Eric Barnes) Events Library - Help? |
[eluser]Devon Lambert[/eluser]
Hello all, Trying to make use of this events library made by Dan Horrigan, and Eric Barnes. https://github.com/dhorrigan/codeigniter-events Unfortunately, I cannot figure out how to properly incorporate it in my code to listen/trigger events. Can someone point me in the direction of a quick example of usage? Thanks.
[eluser]Eric Barnes[/eluser]
Hi Devon, Here is an example to try and help. 1. Auto load the events library 2. Register a new hook inside your code. EX: Code: $data = array(); 3. Create an events class file. Which you will need to manually load first. I normally have these loaded based on if a module is active but you can do it any way you wish. An example file would be something like: Code: <?php defined('BASEPATH') or exit('No direct script access allowed'); Basically the construct registers the method_name to the edit_user hook. Here is an example where I integrated this into pyrocms which may help more: https://github.com/pyrocms/pyrocms/commi...d38eb8c74b
[eluser]Devon Lambert[/eluser]
Thanks for the fast response Eric. I'll play around with this some more in the AM. :-)
[eluser]Devon Lambert[/eluser]
Thanks again for your help on this Eric. It works like a charm. I have 1 final question/stumping block that I'm facing... How would you handle the situation of multiple events which in turn require multiple functions to fire given certain scenarios. To put this another way, I am trying to use this library in a user experience module. 1) Users are awarded experience points for completing certain actions on my site. 2) The module would listen for the required action and once complete would award the user the appropriate amount of points. Obviously, your events library fits this scenario perfectly. However, let's say I have 20 actions that a user can complete for a given event, then wouldn't my "Experience_Events" class look something like below: Code: class Events_Experience { Seems like a bit of overkill for one class, no? :-)
[eluser]Eric Barnes[/eluser]
Yes you could it that way or just have it call one method which in turns does everything it needs: Code: class Events_Experience {
[eluser]Unknown[/eluser]
this event library really great but i still not understand where should i create the event class file should i add in library folder but it has same filename with real library or i have to do modification in real events.php file?
[eluser]Eric Barnes[/eluser]
That is really up to you to decide. I always use the thirdparty folder to house anything related to that. Then scan it and initialize the classes that will be calling the hooks. This has been added to the pyrocms dev branch on github if you want to see how it was done in it. |
Welcome Guest, Not a member yet? Register Sign In |