Skip to content
Events library to build extendible applications
Branch: master
Clone or download
#3 Compare This branch is 5 commits ahead, 1 commit behind ericlbarnes:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Added all files Jul 10, 2011
core Updated for CI3 Dec 12, 2015
libraries Added all files Jul 10, 2011
tests Added all files Jul 10, 2011 Add extension to the core to allow library like loading of event hand… Jun 1, 2014 Added all files Jul 10, 2011

CodeIgniter Events Library

Build extendible applications with an events system.

Version 1.0.0

Additions (Core Extention)

Public Methods


Registers a Callback for a given event

  • $event string
  • $callback array
  • Example: Events::register('test_string', array('Class_name', 'string_return'));


Triggers an event and returns the results.

  • $event string - The name of the event
  • $data mixed - Any data that is to be passed to the listener
  • $return_type string - Either 'array', 'json', 'serialized', or 'string'
  • Example: Events::trigger('test_string', 'test', 'string');


Checks if the event has any listeners

  • $event string - The name of the event
  • return bool

Usage Overview

All Events functions are static.

You can add a listener to an event with the register() function:

Events::register('event_name_here', array('class_name_or_object_ref', 'method_name'));

The second parameter of register() is an array that is callable via call_user_func().

You trigger an Event by calling the trigger() function:

$event_return = Events::trigger('event_name_here', $data, 'string');

The 3rd parameter is the type of data you wish trigger() to return. Your options are as follows:

  • 'array'
  • 'json'
  • 'serialized'
  • 'string' (the default)

Example Usage

Because events need to be registered before being used it is a good idea to have a system in place to load any of these before you trigger any events.

Here is an example loading the event handler to register the event.

// Example Welcome Controller

class Welcome extends CI_Controller {

	public function __construct()
		// Load Library


	public function index()
		var_dump(Events::trigger('test_string', 'test', 'string'));

// Example events/test.php

class Test {

	public function __construct()
		Events::register('test_string', array($this, 'string_return'));

	public function string_return()
		return 'I returned a string. Cakes and Pies!';
You can’t perform that action at this time.