ExpressionEngine Docs

Role Group Model

class ExpressionEngine\Model\Role\RoleGroup

Properties

Required

Optional

Relationships

Roles

Member instances are assigned to role as Primary Role.

Members

Members that are assigned to role. May or may not intersect with PrimaryMembers.

Note: To get full list of members assigned to role, use getAllMembers() function.

Methods

This model has no methods.

Examples

Get a Role Group by ID

$role_id = 6;
$roleGroup = ee('Model')->get('RoleGroup', $role_id)->first();

Edit a Role Group Name

$roleGroup = ee('Model')->get('RoleGroup', 6)->first();
$roleGroup->name = 'Marvel Members';

// Validate and Save.
$result = $roleGroup->validate();

if ($result->isValid())
{
  $roleGroup->save();
}

Create a Role Group

// Create a Role Model
$roleGroup = ee('Model')->make('RoleGroup');

// Set the Require field
$roleGroup->name = 'DC Members';

// Validate and Save.
$result = $roleGroup->validate();

if ($result->isValid())
{
  $roleGroup->save();
}

// the ID is now available:
$roleGroup->group_id;

Add Roles to a Role Group

// Role IDs to add to Role Group.
$role_members = array(1,2,3);

// Use the Roles relationship to get each Role object.
$roleGroup->Roles = ee('Model')->get('Role', $role_members)->all();

// Validate and Save.
$result = $roleGroup->validate();

if ($result->isValid())
{
  $roleGroup->save();
}