Display group name?
Permalink
Hi guys,
Just wondered if anyone could help me out, i'm trying to display the 'group name' of a logged in member. I've achieved displaying their member name and a few other attributes using the following code:
I've tried replacing the getUserName with 'getGroupMemberType()' and 'getGroupMemberName()' but having no luck, and they were just guesses. Am I calling the wrong attributes or can groups not be called in the same way?
Thanks for any help!
Just wondered if anyone could help me out, i'm trying to display the 'group name' of a logged in member. I've achieved displaying their member name and a few other attributes using the following code:
$u = new User(); $ui = UserInfo::getByID($u->getUserID()); print $ui->getUserName();
I've tried replacing the getUserName with 'getGroupMemberType()' and 'getGroupMemberName()' but having no luck, and they were just guesses. Am I calling the wrong attributes or can groups not be called in the same way?
Thanks for any help!
since a user can be in multiple groups you have to specify what group object you want to check.
Thanks, does that have something to do with:
In my scenario, I will be adding users manually, and assigning each one to either group a, b, c, or d (for example), so I only need it to return one value. Is it possible to return that single value? Not too sure what group object I will need to declare since they will all be in individual groups... (I'm sure i'll be making more of a meal of this than is needed)!
Still getting used to C5 so you'll have to bare with me at the mo :)
$g = Group::getByName('groupname');
In my scenario, I will be adding users manually, and assigning each one to either group a, b, c, or d (for example), so I only need it to return one value. Is it possible to return that single value? Not too sure what group object I will need to declare since they will all be in individual groups... (I'm sure i'll be making more of a meal of this than is needed)!
Still getting used to C5 so you'll have to bare with me at the mo :)
really rough example
if there is only one group then that should display the name.
$u=new User(); $groups = $u->getUserGroups(); foreach($groups as $group){ echo $group; }
Thanks, that's now showing the group the user belongs too but also 'registered users' and 'guest' on either side of it. Is there any way of excluding them so they don't show up as well? Appreciate the help!
so the order is like
? There are several possibilities, try something like this.
array( [Registered Users groupID]=>Registered Users [Group b groupID]=>Group b [GuestgroupID]=>Guest )
$u=new User(); $groups=$u->getUserGroups(); foreach($groups as $key=>$group){ if($key!==1&&$key!==2){ echo $group; } }
Brilliant, that sorted it! Thanks again for your help :-)