I can add a member to 'GroupX' like this:
$member->addToGroupByCode('GroupX');
How can I remove a member from 'GroupX'?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
I can add a member to 'GroupX' like this:
$member->addToGroupByCode('GroupX');
How can I remove a member from 'GroupX'?
According to 'cms/code/MemberTableField.php':
$member = DataObject::get_by_id('Member', $memberID);
$member->Groups()->remove($groupID);
Thanks! How can I remove the $groupID for the group named "GroupX"?
I *think* you are able to put a where clause in the relationship getter...
$member->Groups("Name='groupname'")->remove($groupID);
swaiba, your code still uses $groupID but I don't know the $groupID.
$doGroup = DataObject::get_one('Group',"Name='GroupX'");
$member->Groups()->remove($doGroup->ID);