title: Symfony/Doctrine/SfGuardPlugin: Redirect to requested page (route), and not referrer
body: <p>I want to be able to take the user to the requested page after login, but this does not happen with sfGuard.
  ** My Register action requires SignIn ;) **</p>
  
  <p>On the listing page [<a href="http://cim/frontend_dev.php/]" rel="nofollow noreferrer">http://cim/frontend_dev.php/]</a>
  -> user clicks the 'Register' link [@register = register/index]
  -> user is taken to 'Signin' page provided by sfGuard
  -> after sign-in, user is taken back to the Listing page (instead of Register)
  This is quite annoying! But logical, because the referrer is the listing page.</p>
  
  <p>How can I change logic to make @register the referrer? Pl help. thanks</p>
  
  <pre><code>public function executeSignin($request)
    {
      $user = $this-&gt;getUser();
      $this-&gt;logMessage('Signin&gt;&gt;&gt; form - isAuth() '.$user-&gt;isAuthenticated(), 'info');
  
      if ($user-&gt;isAuthenticated())
      {
          $this-&gt;getUser()-&gt;setAttribute('tenant', $this-&gt;getUser()-&gt;getGuardUser()-&gt;sfuser-&gt;Tenant-&gt;getID());
          return $this-&gt;redirect($user-&gt;getReferer($request-&gt;getReferer()));
      }
  
      $class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin'); 
      $this-&gt;form = new $class();
      $referer = $user-&gt;getReferer($request-&gt;getReferer());
      $this-&gt;logMessage('Signin&gt;&gt;&gt; referer: '.$referer, 'info');
      $this-&gt;logMessage('Signin&gt;&gt;&gt; referer: '.$request-&gt;getReferer(), 'info');
  
      if ($request-&gt;isMethod('post'))
      {
        $this-&gt;form-&gt;bind($request-&gt;getParameter('signin'));
        if ($this-&gt;form-&gt;isValid())
        {
          $values = $this-&gt;form-&gt;getValues(); 
          $this-&gt;getUser()-&gt;signin($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);
          $this-&gt;getUser()-&gt;setAttribute('tenant', $this-&gt;getUser()-&gt;getGuardUser()-&gt;sfuser-&gt;Tenant-&gt;getID());
  
          $this-&gt;logMessage('Signin&gt;&gt;&gt; sfUrl | @homepage: '.sfConfig::get('app_sf_guard_plugin_success_signin_url','@homepage'), 'info');
          return $this-&gt;redirect("" != $referer ? $referer : sfConfig::get('app_sf_guard_plugin_success_signin_url','@homepage'));
        }
      }
      else
      {
        if ($request-&gt;isXmlHttpRequest())
        {
          $this-&gt;getResponse()-&gt;setHeaderOnly(true);
          $this-&gt;getResponse()-&gt;setStatusCode(401);
  
          return sfView::NONE;
        }
  
        // if we have been forwarded, then the referer is the current URL
        // if not, this is the referer of the current request
        $user-&gt;setReferer($this-&gt;getContext()-&gt;getActionStack()-&gt;getSize() &gt; 1 ? $request-&gt;getUri() : $request-&gt;getReferer());
  
        $this-&gt;logMessage('Signin&gt;&gt;&gt; oldy: '.$request-&gt;getUri(), 'info');
        $this-&gt;logMessage('Signin&gt;&gt;&gt; oldy: '.$request-&gt;getReferer(), 'info');
  
        $module = sfConfig::get('sf_login_module');
        if ($this-&gt;getModuleName() != $module)
        {
          return $this-&gt;redirect($module.'/'.sfConfig::get('sf_login_action'));
        }
  
        $this-&gt;getResponse()-&gt;setStatusCode(401);
      }
    }
  </code></pre>
  
  <p>Trace:</p>
  
  <pre><code>May 27 10:10:14 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signin" (/login)
  May 27 10:10:14 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signout" (/logout)
  May 27 10:10:14 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_password" (/request_password)
  May 27 10:10:14 symfony [info] {sfPatternRouting} Match route "register" (/register) for /register with parameters array (  'module' =&gt; 'register',  'action' =&gt; 'index',)
  May 27 10:10:14 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
  May 27 10:10:14 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
  May 27 10:10:14 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
  May 27 10:10:14 symfony [info] {registerActions} Call "registerActions-&gt;executeIndex()"
  May 27 10:10:14 symfony [info] {sfFrontWebController} Redirect to "http://cim/frontend_dev.php/login"
  May 27 10:10:14 symfony [info] {sfWebResponse} Send status "HTTP/1.1 302 Found"
  May 27 10:10:14 symfony [info] {sfWebResponse} Send header "Location: http://cim/frontend_dev.php/login"
  May 27 10:10:14 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
  May 27 10:10:14 symfony [info] {sfWebDebugLogger} Configuration 13.39 ms (9)
  May 27 10:10:14 symfony [info] {sfWebDebugLogger} Factories 50.02 ms (1)
  May 27 10:10:14 symfony [info] {sfWebDebugLogger} Action "register/index" 1.94 ms (1)
  May 27 10:10:14 symfony [info] {sfWebResponse} Send content (104 o)
  May 27 10:10:16 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signin" (/login)
  May 27 10:10:16 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_signout" (/logout)
  May 27 10:10:16 symfony [info] {sfPatternRouting} Connect sfRoute "sf_guard_password" (/request_password)
  May 27 10:10:16 symfony [info] {sfPatternRouting} Match route "sf_guard_signin" (/login) for /login with parameters array (  'module' =&gt; 'sfGuardAuth',  'action' =&gt; 'signin',)
  May 27 10:10:16 symfony [info] {sfFilterChain} Executing filter "sfGuardRememberMeFilter"
  May 27 10:10:16 symfony [info] {sfFilterChain} Executing filter "sfRenderingFilter"
  May 27 10:10:16 symfony [info] {sfFilterChain} Executing filter "sfExecutionFilter"
  May 27 10:10:16 symfony [info] {sfGuardAuthActions} Call "sfGuardAuthActions-&gt;executeSignin()"
  May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin&gt;&gt;&gt; form - isAuth() 
  May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin&gt;&gt;&gt; referer: http://cim/frontend_dev.php/
  May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin&gt;&gt;&gt; referer: http://cim/frontend_dev.php/
  May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin&gt;&gt;&gt; oldy: http://cim/frontend_dev.php/login
  May 27 10:10:16 symfony [info] {sfGuardAuthActions} Signin&gt;&gt;&gt; oldy: http://cim/frontend_dev.php/
  May 27 10:10:16 symfony [info] {sfPHPView} Render "D:/projects/cim/plugins/sfDoctrineGuardPlugin/modules/sfGuardAuth/templates/signinSuccess.php"
  May 27 10:10:16 symfony [info] {sfPHPView} Decorate content with "D:\projects\cim\apps\frontend\templates/layout.php"
  May 27 10:10:16 symfony [info] {sfPHPView} Render "D:\projects\cim\apps\frontend\templates/layout.php"
  May 27 10:10:16 symfony [info] {main} Get slot "title"
  May 27 10:10:16 symfony [info] {sfWebResponse} Send status "HTTP/1.1 401 Unauthorized"
  May 27 10:10:16 symfony [info] {sfWebResponse} Send header "Content-Type: text/html; charset=utf-8"
  May 27 10:10:16 symfony [info] {sfWebDebugLogger} Configuration 16.06 ms (10)
  May 27 10:10:16 symfony [info] {sfWebDebugLogger} Factories 50.00 ms (1)
  May 27 10:10:16 symfony [info] {sfWebDebugLogger} Action "sfGuardAuth/signin" 14.53 ms (1)
  May 27 10:10:16 symfony [info] {sfWebDebugLogger} View "Success" for "sfGuardAuth/signin" 34.44 ms (1)
  May 27 10:10:16 symfony [info] {sfWebResponse} Send content (38057 o)
  </code></pre>