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.

General Questions /

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

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

Member Management: Remove Group by Code


Reply


6 Posts   1139 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, 215 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, 1798 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, 1798 Posts

12 February 2011 at 2:08am

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


?