0

on my Joomla-CLI-Script I would like to fetch all user-ids which belong to a specific group.

My script so far:

    // $groups = groups that are set in global params
    if(!empty($groups));
    {       
        foreach($groups as $group) :
            $groupmembers = JAccess::getUsersByGroup($group);   

            foreach($groupmembers as $groupmember) :
                $user = JFactory::getUser($groupmember);
                $userarray[] = array(   "email" => $user->email,
                                        "userid" => $user->id); 
            endforeach;
        endforeach;
    }

Now I'm getting this error: Trying to get property of non-object in /var/www/web1/htdocs/libraries/joomla/factory.php on line 246

When I edit factory.php and go to line 246, I'm getting this line:

elseif (is_string($id) || $instance->id !== $id)

So I guess my CLI does not create an instance - but how can I do that?

1

If you simply want to get the ID's and email's of all users that belong to a specific group, you can do the following:

$group_id       = 8;
$usersByGroup   = JAccess::getUsersByGroup($group_id);

foreach ($usersByGroup as $id)
{
    $user = JFactory::getUser($id);
    echo $id;
    echo $user->email;
}

Of course, change 8 to the ID of the group you wish to target.

  • Hey Lodder, I thought that I'm doing exactly this? For each group that is given I'm having the foreach-loop which is trying to get the information about that user. But unfortunately I'm getting the error I was speaking of :-( – MyFault Jun 29 '15 at 14:24
  • @MyFault - So you're getting the same error even when you use my code instead of yours? Have you ensured you're importing the Joomla API in your CLI script? – Lodder Jun 29 '15 at 14:28
  • Yes - I'm getting the same error. I am including the following joomla-libs: d.pr/4STE – MyFault Jun 29 '15 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.