Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Member Management: Remove Group by Code


Go to End


6 Posts   2264 Views

Avatar
DeklinKelly

Community Member, 197 Posts

11 February 2011 at 4:42am

I can add a member to 'GroupX' like this:

$member->addToGroupByCode('GroupX');

How can I remove a member from 'GroupX'?

Avatar
Devlin

Community Member, 344 Posts

11 February 2011 at 9:42pm

According to 'cms/code/MemberTableField.php':

$member = DataObject::get_by_id('Member', $memberID);
$member->Groups()->remove($groupID);

Avatar
DeklinKelly

Community Member, 197 Posts

12 February 2011 at 1:47am

Thanks! How can I remove the $groupID for the group named "GroupX"?

Avatar
swaiba

Forum Moderator, 1899 Posts

12 February 2011 at 1:58am

I *think* you are able to put a where clause in the relationship getter...

$member->Groups("Name='groupname'")->remove($groupID);

Avatar
DeklinKelly

Community Member, 197 Posts

12 February 2011 at 2:03am

swaiba, your code still uses $groupID but I don't know the $groupID.

Avatar
swaiba

Forum Moderator, 1899 Posts

12 February 2011 at 2:08am

$doGroup = DataObject::get_one('Group',"Name='GroupX'");
$member->Groups()->remove($doGroup->ID);

?