Developing a Codeigniter game Developing a Codeigniter game codeigniter codeigniter

Developing a Codeigniter game


I use the Symfony Event Dispatcher component to do something like this; the component can be installed without using the Symfony Framework, so you can use it with CodeIgniter, but there might already be something similar available to you; I don't know CodeIgniter.

The Event Dispatcher is a generic implementation of the Observer Pattern.

  • I have a list of modules which register themselves as observers for any actions which they handle
  • Each request passes through an action (e.g. "townview")
  • My controller just creates an Event with whatever the action was as the name; the Event Dispatcher system then finds any modules which claim to be able to handle that action and passes over control to them

This way the main controller doesn't have to change, no matter how many actions you have; it just creates an event and throws it out through the dispatcher; if it's not handled it throws a massive error (in DEV) or a nice one (in PROD).

This is especially useful in our application, where we have lots of optional components that can be switched on or off for different users / clients; no complex logic in the controller at all, I just don't register the modules if they aren't enabled for a client.