7

要在 Joomla 2.5.15 中获取用户组 ID,我按照此处的 Joomla 文档中的文档进行操作

我的代码如下所示:

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

但是这段代码产生了错误:注意:未定义的属性:JUser::$gid in 输出中没有任何组 id。

4

3 回答 3

14

尝试使用这个:

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

foreach ($groups as $group)
{
    echo '<p>Group = ' . $group . '</p>';
}
于 2013-08-23T16:31:01.247 回答
1
jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($user_id, false);
var_dump($groups);
于 2014-06-24T13:00:35.310 回答
-1

来自文档

$user = JFactory::getUser(99); 
echo "<p>Your usertype is {$user->usertype} which has a group id of {$user->gid}.</p>";
于 2013-08-23T16:55:15.533 回答