Вопрос

Is it possible to get a list of users of a specific usergroup, for exmplample group "Registered Users", with a simple href-link of their UserID?

Thanks!

Это было полезно?

Решение

Registered users belong to the group with id 2. I tried to find group names constant somewhere, but I failed when I was researching for my project, so I ended up making my own constants.

Anyway, to get users who belong to a group, you can use

$registeredUsers = JAccess::getUsersByGroup(2); // in my project it was $self::REGISTERED_GROUP

Add

jimport('joomla.access.access');
jimport('joomla.user.user');

before if neccessary classes are not loaded.

Then you could do

foreach($registeredUsers as $user_id) {
    $user = JFactory::getUser($user_id);
    echo $user->name;
}

Important: Make sure before selecting users using the id passed in the link that it belongs to id group list which you want exposed. I guess you wouldn't want to expose super administrator usernames etc

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top