How to implement achievement system in CodeIgniter

In this post, I'm going to implement a reward system using PHP, similar to the current console generation's game achievements. Certain user interactions which satisfy the game's predefined set of requirements will trigger an event of showing the reward. E.g. Survive a fall from 400m will unlock the achievement of "Die Hard".

How to implement this feature in PHP? Since I've been working on CodeIgniter MVC, I shall introduce you a library, simply called as "CodeIgniter Events" by Eric Barnes and Dan Horrigan.

Steps

  1. Download the latest CodeIgniter here, version 2.1.3 as of writing 
  2. Download CodeIgniter Events library here
  3. Add the autoload line in config/autoload.php and put the events.php in application/libraries folder

Tasks

Whenever user types more than 5 characters into a text field and clicks 'Send' button, it will trigger the event class and show the achievement text.

Solution



4 comments: