Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleds committed Apr 29, 2012
1 parent 683c66e commit 57f4fd3
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
How to use
Getting started
----------
First, you have to create a new class where you will define all your rules. Let's start with this:

require_once "SimpleRoles.php";

class Ability extends SimpleRoles {

function __construct($user) {
parent::__construct();

// You should define here your rules
}

}

We place our rules inside the `__construct` function.

function __construct($user) {
parent::__construct();

// We put the current user roles in $user_roles.
// Please note that you can use whatever method you
// prefer for checking role membership.
$user_roles = array();
if($user != null)
$user_roles = $user->getRoles();

if(in_array('admin', $user_roles)) {
$this->can('read_article');
$this->can('write_article');
$this->can('delete_article');
}

if(in_array('moderator', $user_roles)) {
$this->can('read_article');
$this->can('write_article');
}

if(in_array('guest', $user_roles)) {
$this->cannot('all');
}
}

0 comments on commit 57f4fd3

Please sign in to comment.