【发布时间】:2013-06-07 17:46:25
【问题描述】:
所以我从后端在 Joomla 中创建了一些自定义用户组。 我将注册用户放在这些自定义组下。 组是这样的-
公开
|— 用户
|—|— 审核员
|—|— Custom_group1
|—|—|— Custom_group2
|—|—|—|— Custom_group3
|—|—|—|—|— 管理员
|—|—|—|—|—|— 超级用户
|—|— Custom_group4
所以,假设user_b 在Custom_group4 组和Custom_group3 下,其中自定义组3 和4 的ID 分别是2 和11(比如说),
MySql 数据库看起来像-
表:#__users
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)
谁能帮帮我?
【问题讨论】: