views:

2131

answers:

2

With Symfony's Action Security if a user has not been identified he will be forwarded to the default login action as defined in the applications settings.yml file. How would I forward the user to the originally requested action after the user is successfully authenticated?

+3  A: 

on first hit to your login action, store referer to the user session:

    if(!$this->getUser()->hasParameter('referer'))
{
  $this->getUser()->setParameter('referer',$this->getRequest()->getReferer();
}

and then when login succedes, redirect user to stored referer with:

$this->redirect($this->getUser()->getParameter('referer');

You have complete example in sfGuardPlugin:

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

deresh
A: 

More simply...

$this->getUser()->setReferer($this->getRequest()->getReferer());

like

setReferer($referer)
{
  if (!$this->hasAttribute('referer'))
    $this->setAttribute('referer', $referer);
}