Home

Permissions

Using canCreate(), canEdit(), canDelete() and canPublish() to manage page type permissions

Often you will want to control which users can create, edit, delete and publish certain page types. For example you may only want high level users to be able to create ContactPage page types, or prevent low level users from deleting HomePage page types. This can easily be achieved by adding these functions to the page type model (usually just before getCMSFields()). Then within the function you can define conditionals which decide whether to return true or false.

So let's say you have created the permission code in this snippet. We can now use that permission code and the canCreate() function to decide whether a particular user can create this page type:

 

Read More >>

Create a Permission Code

Ever wanted to add an extra permission code so that when you add permissions to a group you can create a custom option? Here's how it's done; Simply add this code to your Page_Controller class as well as adding "implements PermissionProvider" on the end of the class definition like so:

That will create two new permission codes: 'USER' and 'SUPERUSER', so you can then call permission::check('USER') anywhere in your code to see if the current user is in a group with USER permissions.

 

Read More >>