Developer Manuals
What do Events do?
Events are an alternative to CodeIgniter hooks. 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":
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Sample Events Class
*
* @package PyroCMS
* @subpackage Sample Module
* @category events
* @author PyroCMS Dev Team
*/
class Events_Sample
// this will be triggered by the Events::trigger('public_controller') code in Public_Controller.php
public function run()
{{
// you can load a model or etc here if you like using $this->ci->load();
return 'The Public Controller has ran';
}}
}
/* End of file events.php */
Which Events are triggered by the core?
A default install has 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 My_Email but can be triggered from anywhere in the application.
Added in version 1.3.0
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.
