Snippets for eZ publish 3: Assigning roles

Predefined variables

  • $roleID: ID of the role
  • $objectID: id of a user or user group content object you want to assign the role to
  • $limitIdent: either null, Subtree or Section
  • $limitValue: either null, a node path string (in case $limitIdent is 'Subtree') or a section id (in case $limitIdent is 'Section')
include_once( 'kernel/classes/ezrole.php' );
$role = eZRole::fetch( $roleID );
$role->assignToUser( $objectID, $limitIdent, $limitValue );

eZRole::expireCache();

include_once( 'kernel/classes/ezcontentcachemanager.php' );
eZContentCacheManager::clearAllContentCache();

include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
eZUser::cleanupCache();