1

我正在使用登录插件(http://rtfm.modx.com/display/ADDON/Login),并且能够使用以下方式获取有关用户的一些信息:

print_r($_SESSION);

但我想知道如何获取该用户的用户组(名称或 ID)。有人知道该怎么做吗?谢谢!

PS:print_r($_SESSION);给我什么:

Array
(
    [modx.user.0.resourceGroups] => Array
    (
        [web] => Array ( ) 
    ) 
    [modx.user.0.attributes]     => Array 
    (
        [web] => Array
        (
            [modAccessContext] => Array
            (
                [web] => Array
                (
                    [0] => Array
                    (
                        [principal] => 0 
                        [authority] => 0 
                        [policy]    => Array ( [load] => 1 ) 
                     ) 
                  )
            ) 
            [modAccessResourceGroup]       => Array ( ) 
            [modAccessCategory]            => Array ( ) 
            [sources.modAccessMediaSource] => Array ( )
        )
    ) 
[modx.user.contextTokens] => Array ( [web] => 2 ) 
[modx.web.user.token]     => modx507e2d531fedb5.20134124_250c977bed72111.66166942 
[modx.web.session.cookie.lifetime] => 0
[modx.user.2.resourceGroups] => Array ( [web] => Array ( [0] => 1 ) ) 
[modx.user.2.attributes] => Array ( [web] => Array ( [modAccessContext] => Array ( [web] => Array ( [0] => Array ( [principal] => 2 [authority] => 9999 [policy] => Array ( [load] => 1 [list] => 1 [view] => 1 [save] => 1 [remove] => 1 [copy] => 1 [view_unpublished] => 1 ) ) ) ) 
[modAccessResourceGroup] => Array ( [1] => Array ( [0] => Array ( [principal] => 2 [authority] => 9999 [policy] => Array ( [load] => 1 [list] => 1 [view] => 1 ) ) ) ) 
[modAccessCategory] => Array ( ) [sources.modAccessMediaSource] => Array ( ) ) ) ) 
4

1 回答 1

2

阅读此 - http://www.shawnwilkerson.com/modx-revolution/2012/03/10/programmatically-working-with-the-moduser-object/您需要的代码示例:

/*
* modUser Groups
*/
$arry = print_r($user->getUserGroups(), true);
$modx->toPlaceHolder('user.groups', $arry);
于 2012-12-13T10:51:43.017 回答