I'm writing a Joomla 2.5 component that I had been developing in Joomla 1.7. I have been using code like this:
$user = JFactory::getUser();
$groups = $user->get('groups');
The $groups array would contain a list of ids with the group name as the index. Joomla 2.5 seems to have scrapped this functionality. I have been unable to find out how to get the group names without directly querying the database. Is there any method for getting a list of the groups a user is a member of without having to resort to querying the database?
Real snippet:
Yes, this changed.
But what you should be using instead is:
or just
getUserGroups
The code I generated below gets the names of all the groups the user is a part of and stores them in the variable $groupNames separated by line breaks:
It technically queries the database but is done via the Joomla API. This is working well for me on Joomla 2.5.
Here it is:
This will print all the user group names to the screen. The user group names are the "keys" of the array $user->groups.
To fix that you need to include false as demonstrated below. Note that 43 is the userid.
More detailed information can be found at http://forum.joomla.org/viewtopic.php?t=530721
Incidentally, if you're interested in a stackoverflow like QnA for Joomla please support http://area51.stackexchange.com/proposals/58842/joomla