我想更改 drupal 7 中所有用户的重定向成功页面。
我在成功登录后在 mysite.com/user
中的登录页面被重定向到页面 mysite.com/user/1
.butr 我想将登录成功重定向页面更改为
mysite.com/node/1
我试过了
function bartik_user_login(&$edit, $account)
{
// Your logic will set $redirection to the desired location
$redirection = 'node/1';
// Unless there is already a redirection going, or the user is trying to reset his password, we redirect to $redirection.
if (empty($_GET['destination'])
&& !is_null($redirection)
&& (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = $redirection; // Should we use $edit['redirect'] instead..?
}
}
答案 0 :(得分:1)
因为 $_GET['destination']
始终存在(在您的情况下为 user/{id}
),因此您的分配 $_GET['destination'] = $redirection
永远不会到达。
只需从 empty($_GET['destination']
条件中删除 if
,您的代码就会起作用:
function bartik_user_login(&$edit, $account)
{
$redirection = 'node/1';
if (!is_null($redirection)
&& (!isset($_POST['form_id']) || $_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = $redirection;
}
}