How would I package an event?

Permalink
I have written 2 events into a site_events.php that are working great. I've also written a dashboard page that modifies some options and has a global on/off switch for the events.

Is there a way to auto-install these two events when I put together my package installer for distribution, or do I need to use some php code to manually move the files around on the server?

ie.

move site_events.php from /packages/packagename to /config

move eventmodel.php from /packages/packagename to /models

torchmedia
 
ryan replied on at Permalink Reply
ryan
You can add an on_start function to your package controller:
<?php
public function on_start() {  
  Events::extend(
  'event handle',
  'class name',
  'method name',
  'packages/'.$this->pkgHandle.'/models/class file name');
}
?>
torchmedia replied on at Permalink Reply
torchmedia
I guess I didn't give enough of an explanation, sorry. I want the events to be run globally, not just for a specific page/package.

Wouldn't your code only run the events on a page that is calling the package?
ryan replied on at Permalink Reply
ryan
That will work globally, give it a shot.
torchmedia replied on at Permalink Reply
torchmedia
It does work perfectly, thank you.

So to be clear, c5 will automatically loop through every /package/packagename/controller.php on any given page load?