Yii framework application module. Adds badge functionality into your Yii app.

Module. With small configuration adds badges (gamification logic) to your app. Custom badge giving logic and custom images.

InstallationAdd custom badgeEventsImagesUpgradeEntertainment


  • PHP 5
  • tested with Yii 1.1.10
  • MySQL, PostgreSQL, SQLite.. (used Yii functions to create tables and insert data)


  • Different database platforms: MySQL, PostgreSQL, SQLite..
  • Assign badges to custom user table (default is "user" but it can be changed)
  • Using custom layout (default: layouts/main)
  • Add your own logic how specific badge is given to user. Your conditions - Add custom badge
  • Given default style for badges, but it's 100% customizable - Images
  • Create your own view files (it will not be overwritten on next version) - Upgrade
  • Cache badges (listed from db)


Copy contents into protected/modules/badger/ (so it comes as protected/modules/badger/).

OR clone it with mercurial

$ cd protected/modules
$ hg clone https://briiC@bitbucket.org/briiC/badger.yii badger

Make your own files (copy from *.original)

Before using badger you must copy some default files and make your own

$ cd protected/modules/badger
$ cp controllers/BadgeController.php.original controllers/BadgeController.php
$ cp models/Badge.php.original models/Badge.php
$ cp views/badge/_list.php.original  views/badge/_list.php
$ cp views/badge/list.php.original  views/badge/list.php
$ cp views/badge/my.php.original  views/badge/my.php
$ cp assets/css/badger.css.original assets/css/badger.css


Module creates new files so you need to give permissions (only for installing part. After that you can set to default permissions)

$ cd protected/modules/
$ sudo chmod -R 0775 badger/
$ sudo chown -R myuser:www-data badger/




              // Badger

      'modules'=> array(

            'badger' => array(
                  //'layout' => '//layouts/mainx', //default: "//layouts/main"
                  //'userTable' => 'userx', // default: "user"
                  'cacheSec' => 3600 * 24, // cache duration. default: 3600

                  // Creates tables and copy necessary files
                  'install' => true, // remove/comment after succesful install
                   // drop all badger tables before installing (fresh install)
                  'dropBeforeInstall' => false, 


There is two params that better must be removed or commented after you successfully run badge module.

  • install - Created tables (two: badge and _user_badge)
  • dropBeforeInstall - Try to drop badger tables before installing

Add your custom badge

Read Add custom badge how to create new bages with custom logic

Give badge to user


$Badge = new Badge;
//$Badge->onSuccess = array( $object, 'notifyUser'); // add custom event after giving badge to user
$badgeIdArr = $Badge->checkAndGiveGroup( get_class($this) );



Please give feedback about installation/configuration process. Which part is not so easy to understand I will try get it more clear for everybody.

Also send bugs, ideas: https://bitbucket.org/briiC/badger.yii/issues/new


Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.