Snippets - Little bits of code to make you happy
Create and use a Permission code
Tweet18 April 2009 | | | Supports v2.4, v2.3
Have you wanted to add an extra permission code that you can add to groups and then use that to test whether a particular user has that permission? Here's how it's done. The permission code it self is added via the Controller class, then you use a permission check anywhere in your site code to check the current user. Like so:
class Page_Controller extends ContentController implements PermissionProvider {
function providePermissions(){
return array(
"USER" => "Just a regular user",
"SUPER_USER" => "A super-duper mega user"
);
}
}
Now, let's say we only wanted users with permission code SUPER_USER to be able to edit a particular page, we could do a Permission::check() inside the canEdit() function like so:
function canEdit($Member = null)
{
return Permission::check('SUPER_USER');
}
For more info on using canEdit() and the other permission functions see this post.
Comments
RSS feed for comments on this page RSS feed for all comments
No one has commented on this page yet.
Post a comment ...
You cannot post comments until you have logged in. Login Here.