管理员登录后,Modx将用户重定向到特定页面

时间:2017-03-18 16:23:21

标签: modx modx-revolution modx-resources modx-templates

我找到了这个插件代码:

<!--?php
if ($modx--->event->name == 'OnManagerLogin') {
    $path = $modx->getOption('base_url',null,MODX_BASE_URL);
    $modx->sendRedirect($path.'manager/?a=69');
}

但我无法使其与MODX Revolution 2.5.0-pl一起使用。 似乎OnManagerLogin根本不起作用。 我是唯一一个?它与此有关吗?

https://github.com/modxcms/revolution/issues/11848

我也试过这个:

$e = $modx->event;
switch( $e->name ) {
case 'OnManagerLogin':
$modx->sendRedirect('http://modx.com',array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
}

但它不起作用。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

Solution is here 使用此代码:

$url = 'http://www.example.com/manager/';

$groups = array(
    'admin_ceremonie' => 'http://www.example.com/manager/?a=resource/update&id=1138',
);

$userId = $user->get('id');
$searchCriteria = array(
    'user' => $userId,
    'key' => 'LoginResourceUrl',
);
$userSetting = $modx->getObject('modUserSetting', $searchCriteria);

if ($userSetting) {
    $url = $userSetting->get('value');
} 
else {
    foreach($groups as $groupName => $pageUrl) {
        if ($user->isMember($groupName)) {
             $url = $pageUrl;
            break;
        }
    }
}

$modx->sendRedirect($url);