要获取Joomla 2.5.15中的用户组ID,我按照Joomla Documentation here
中的文档进行操作我的代码如下所示:
$user = JFactory::getUser();
echo "<p>Your group id is {$user->gid}.</p>";
但是这段代码产生错误:注意:未定义的属性:JUser :: $ gid in 输出中没有任何组ID。
答案 0 :(得分:13)
尝试使用:
$user = JFactory::getUser();
$groups = $user->get('groups');
foreach ($groups as $group)
{
echo '<p>Group = ' . $group . '</p>';
}
答案 1 :(得分:1)
jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($user_id, false);
var_dump($groups);
答案 2 :(得分:-1)
$user = JFactory::getUser(99);
echo "<p>Your usertype is {$user->usertype} which has a group id of {$user->gid}.</p>";