getUserGroupNames() doesn't take any arguments. It gets the groups of the currently logged-in user.
If you're previewing from the Manager, you're not logged in in the front end. Try putting the Login snippet on a page and logging in before checking the user groups.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
Ok I understand.
That being said, is there a way to find out what user group(s) a user belongs to via code? Not needing to to be logged in?
-
☆ A M B ☆
- 24,524 Posts
Doesn't look like there is a documented API function for getting data on a specified user.
Hrm, well I guess I'll have to learn modx DB API. I can achive what I need with regualar php and mysql and just grab the info from the DB. But I'd like to use modx.
-
☆ A M B ☆
- 24,524 Posts
I found something somewhat similar here
http://www.unchi.co.uk/2010/10/31/get-all-members-of-a-user-group-in-modx-revolution/
There should be a way, though, of getting an object of type "User" and passing it a parameter of the username you're interested in, then getting the groups that user belongs to.
$user = $modx->getObject('modUser', $userId);
$groups = $user->getUserGroupNames();
from this
http://www.shawnwilkerson.com/modx-revolution/2012/03/10/programmatically-working-with-the-moduser-object/
[ed. note: sottwell last edited this post 14 years, 3 months ago.]