joomla未显示用户组php的完整地图

joomla未显示用户组php的完整地图,php,mysql,joomla,Php,Mysql,Joomla,因此,我从后端在Joomla中创建了一些自定义用户组。 我将注册用户放在这些自定义组下。 团体是这样的- 公开的 |-使用者 |-|-审核员 |-|-自定义组1 |-|-|-自定义组2 |-|-|-|-自定义组3 |-|-|-|-|-管理员 |-|-|-|-|-|-超级用户 |-|-自定义组4 假设用户_b在组Custom_group4下,也在Custom_group3下,其中Custom组3和4的ID分别为2和11, MySql数据库看起来像- 表:\ u用户 表:\用户\用户组\映射 您可以

因此,我从后端在Joomla中创建了一些自定义用户组。 我将注册用户放在这些自定义组下。 团体是这样的-

公开的 |-使用者 |-|-审核员 |-|-自定义组1 |-|-|-自定义组2 |-|-|-|-自定义组3 |-|-|-|-|-管理员 |-|-|-|-|-|-超级用户 |-|-自定义组4

假设用户_b在组Custom_group4下,也在Custom_group3下,其中Custom组3和4的ID分别为2和11, MySql数据库看起来像-

表:\ u用户

表:\用户\用户组\映射

您可以看到为用户id 524分配了两个组。 现在我有了这个PHP代码来获取useruser id-524的组id

        $user = JFactory::getUser();
        $userId = $user->id;
        $db = JFactory::getDbo();
        $recursive = False;

        // Build the database query to get the rules for the asset.
        $query  = $db->getQuery(true);
        $query->select('ug.group_id');
        $query->from('#__user_usergroup_map AS ug');
        $query->leftJoin('#__users AS a ON a.id = ug.user_id');
        $query->where('a.id = '.(int) $userId);

        // Execute the query and load the rules from the result.
        $db->setQuery($query);
        $result = $db->loadResult();
        print_r((array)$result);
其中,我得到了输出-

Array([0] => 2)
但我希望它是数组[0]=>2,[1]=>11

有人能帮我吗?

解决了

我查看并发现了一个类似的函数,使用了与预期类似的querybetter

这是代码的一部分-

        $query  = $db->getQuery(true);
        $query->select($recursive ? 'b.id' : 'a.id');
        $query->from('#__user_usergroup_map AS map');
        $query->where('map.user_id = '.(int) $userId);
        $query->leftJoin('#__usergroups AS a ON a.id = map.group_id');

        // If we want the rules cascading up to the global asset node we need a self-join.
        if ($recursive) {
                $query->leftJoin('#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
        }

        // Execute the query and load the rules from the result.
        $db->setQuery($query);
        $result = $db->loadResultArray();
这就是我想要的-

Array ( [0] => 2 [1] => 11 )
谢谢谷歌

        $query  = $db->getQuery(true);
        $query->select($recursive ? 'b.id' : 'a.id');
        $query->from('#__user_usergroup_map AS map');
        $query->where('map.user_id = '.(int) $userId);
        $query->leftJoin('#__usergroups AS a ON a.id = map.group_id');

        // If we want the rules cascading up to the global asset node we need a self-join.
        if ($recursive) {
                $query->leftJoin('#__usergroups AS b ON b.lft <= a.lft AND b.rgt >= a.rgt');
        }

        // Execute the query and load the rules from the result.
        $db->setQuery($query);
        $result = $db->loadResultArray();
jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser(526, False); //526 is the user_id for user b
print_r($groups);
Array ( [0] => 2 [1] => 11 )