我知道在成功登录用户后我可以重定向到网址:
return $this->redirect()->toUrl('/user/login?redirect=http://www.myurl.com');
现在,我想对注册路线做同样的事情:
'sso-post-login' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/sso-post-login',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'sso-post-login',
),
'may_terminate' => true,
),
),
但以下不起作用:
return $this->redirect()->toUrl('/user/login?redirect=/sso-post-login');
它没有击中我的行动:
public function ssoPostLoginAction() {
error_log("In sso post login action");
$originUrl = Common::getCookie('sso_post_login', $this->getRequest());
$sessionCookie = Common::getCookie('PHPSESSID', $this->getRequest());
if (null != $sessionCookie && null != $this->getUserService()->getAuthService()->getIdentity()) {
$email = $this->getUserService()->getAuthService()->getIdentity()->getEmail();
$jwtCredentials = $this->buildJWTLoginToken($email);
$originUrl .= "?jwt=" . $jwtCredentials;
return $this->redirect()->toUrl($originUrl);
}
}
登录完成后,它只是重定向到主页面。
答案 0 :(得分:2)
您是否有特殊原因想要将完整(绝对)网址添加到redirect
param?
你可以这样做:
return $this->redirect()->toUrl("/user/login?redirect=".$this->url()->fromRoute('sso-post-login', [], ['force_canonical' => true]));
force_canonical
选项会生成完整的网址(包括您的主机名)