简体   繁体   English

使用PHP获取Joomla中的用户组ID

[英]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 要在Joomla 2.5.15中获取用户组ID,我在此处遵循Joomla文档中的文档

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. 但是这段代码产生错误:注意:未定义属性:JUser :: $ gid in输出中没有任何组ID。

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 来自DOCS

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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