[英]joomla not showing full map of user group php
因此,我从后端在Joomla中创建了一些自定义用户组。 我将注册用户置于这些自定义组下。 团体就像这样-
上市
| —用户
| — | —审核员
| — | — Custom_group1
| — | — | — Custom_group2
| — | — || — | — Custom_group3
| — | — || — |||| —管理员
| — | — ||||||||| —超级用户
| — | — Custom_group4
因此,假设user_b
在Custom_group4
组Custom_group4
,也在Custom_group3
下,其中自定义组3和4的ID分别为2和11(例如),则MySql数据库看起来像-
表格:#__个用户
id name username email password
523 User A user_a user_a@mysite.com blablabla...
524 User B user_b user_b@mysite.com blablabla...
表格:#__ user_usergroup_map
user_id(Foreign Key to #__users.id) group_id(Foreign Key to #__usergroups.id)
523 8
524 2
524 11
您可以看到为用户ID 524分配了两个组。现在,我有了此PHP代码来获取用户的组ID(用户ID-524)
$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)
但我希望它是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 )
谢谢谷歌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.