Symfony Action Security - 成功验证后如何转发?

Ale*_*lex 1 php security action symfony1

使用Symfony的Action Security如果用户尚未被识别,他将被转发到application settings.yml文件中定义的默认登录操作.用户成功通过身份验证后,如何将用户转发到最初请求的操作?

小智 8

首次点击登录操作时,将referer存储到用户会话:

if(!$this->getUser()->hasParameter('referer'))
{
  $this->getUser()->setParameter('referer',$this->getRequest()->getReferer());
}
Run Code Online (Sandbox Code Playgroud)

然后当登录成功时,将用户重定向到存储的referer:

$this->redirect($this->getUser()->getParameter('referer'));
Run Code Online (Sandbox Code Playgroud)

你在sfGuardPlugin中有完整的例子:

http://www.symfony-project.org/plugins/sfGuardPlugin