PyroCMS 2.0 Documentation
Events
What are Events?
Events allow you add your own functionality to the PyroCMS core by hooking into preset points in the code called triggers. There are several triggers already in place in the PyroCMS core that allow you to do things within your code when other parts of PyroCMS run.
Using Events in your modules
Create an events.php file in the root of your module (it will be autoloaded when PyroCMS starts to run). Below is an example file from a module named "Sample":
In the above example, the Events_Sample registers the function 'run' to run when the 'public_controller' trigger is called in PyroCMS.
It is important to note that some triggers pass data that you can use in your function as well.
PyroCMS Triggers
PyroCMS includes the following event triggers:
| Events::trigger('public_controller') | This is triggered when the Public_Controller begins to run. |
| Events::trigger('email', $data, 'array') | This is used to send an email. The second parameter is the data to send along, third parameter is the type of response you expect. The sending is done by an event registered in system/cms/modules/templates/events.php but can be triggered from anywhere in the application. |
| Events::trigger('post_user_login') | This is triggered immediately after a user successfully logs in via domain.com/users/login |
| Events::trigger('post_user_register', $id) | This is triggered immediately after a user registers. The newly created user id is passed along. |
| Events::trigger('post_user_activation', $id) | Triggered when a user successfully activates by following the activation link in the welcome email. The user's id is passed to your event. |
| Events::trigger('pre_user_logout') | Triggered right before the user's session is destroyed. |
| Events::trigger('post_user_update') | Runs after a user's profile edits have been saved. |
