简体   繁体   中英

Get user group id in Joomla with PHP

To get the user group id in Joomla 2.5.15, I followed the documentation in Joomla Documentation here

My code looks like this:

$user = JFactory::getUser();
echo "<p>Your group id is {$user->gid}.</p>";

But this code is producing the error: Notice: Undefined property: JUser::$gid in Without any group id in the output.

Try using this:

$user   = JFactory::getUser();
$groups = $user->get('groups');

foreach ($groups as $group)
{
    echo '<p>Group = ' . $group . '</p>';
}
jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($user_id, false);
var_dump($groups);

FROM DOCS

$user = JFactory::getUser(99); 
echo "<p>Your usertype is {$user->usertype} which has a group id of {$user->gid}.</p>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM