Legacy Documentation
You are using the documentation for version 3.5.17. Go here for the latest version or check here for your available upgrades to the latest version.
Permission Service¶
Simple Example¶
The permission service checks for member authorization as indicated in the session userdata. Superadmins automatically have permission.
To check for exactly 1 permission:
if (ee('Permission')->has('can_edit_all_comments'))
{
$this->show_form();
}
To check for the existence of at least one permission among a list of permissions:
if (ee('Permission')->hasAny('can_create_template_partials', 'can_edit_template_partials', 'can_delete_template_partials'))
{
$this->show_header();
}
To check for the existence of all listed permissions:
$can_delete = ee('Permission')->hasAll('can_delete_all_comments', 'can_delete_own_comments')
Permission Service Methods¶
-
class
EllisLab\ExpressionEngine\Service\Permission\
Permission
¶
-
EllisLab\ExpressionEngine\Service\Permission\Permission::
has
($permission)¶ Checks a session object for a single permission
Parameters: - $permission (string) – A single permission name
Returns: TRUE if allowed FALSE if not
Return type: Boolean
-
EllisLab\ExpressionEngine\Service\Permission\Permission::
hasAny
($permission)¶ Checks a session object for any matches against a collection of permissions, from one on up.
Parameters: - $permission (mixed) – Any number of permission names
Returns: TRUE if allowed FALSE if not
Return type: Boolean
-
EllisLab\ExpressionEngine\Service\Permission\Permission::
hasAll
($permission)¶ Checks a session object matches all permissions in a collection of permissions, from one on up.
Parameters: - $permission (mixed) – Any number of permission names
Returns: TRUE if allowed FALSE if not
Return type: Boolean