sfGuard redirection after login
Got this from a thread ...:
This may or may not help, but if you look on the documentation for sfGuard:
http://trac.symfony-project.com/wiki/sfGuardPlugin
... you'll notice a setting to "Customize sfGuardAuth redirect handling."
all:
sf_guard_plugin:
success_signin_url: @my_route?param=value # the plugin use the referer as default
success_signout_url: module/action # the plugin use the referer as default
But it seems that that may only send you to a specific page after login instead of the requested page. I've accomplished what you're trying to do by simply adding a "return url" field to the login page via GET string and then adding a hidden variable to the login like so:
In the routing file:
sf_guard_signin:
url: /login
param: { module: sfGuardAuth, action: signin }
sf_guard_signin_and_return:
url: /login/:return
param: { module: sfGuardAuth, action: signin }
In your action:
<?php if ($sf_context->getModuleName() != 'sfGuardAuth' && $sf_context->getActionName() != 'signin'): ?>
<?php echo input_hidden_tag('referer', $sf_context->getModuleName().'/'.$sf_context->getActionName()) ?>
<?php elseif ($sf_params->get('return') != ''):?>
<?php echo input_hidden_tag('referer', urldecode($sf_params->get('return'))) ?>
<?php else: ?>
<?php echo input_hidden_tag('referer', 'dashboard') ?>
<?php endif ?>
Then, to have someone login and be redirected to the original page, you can do something like this:
Log in to <?php echo link_to('comment', sprintf('@sf_guard_signin_and_return?return=%s/%s?id=%d',
urlencode($sf_context->getModuleName(),
$sf_context->getActionName(),
$object->getId()))
?>
all:
sf_guard_plugin:
success_signin_url: @my_route?param=value # the plugin use the referer as default
success_signout_url: module/action # the plugin use the referer as default
sf_guard_signin:
url: /login
param: { module: sfGuardAuth, action: signin }
sf_guard_signin_and_return:
url: /login/:return
param: { module: sfGuardAuth, action: signin }
<?php if ($sf_context->getModuleName() != 'sfGuardAuth' && $sf_context->getActionName() != 'signin'): ?>
<?php echo input_hidden_tag('referer', $sf_context->getModuleName().'/'.$sf_context->getActionName()) ?>
<?php elseif ($sf_params->get('return') != ''):?>
<?php echo input_hidden_tag('referer', urldecode($sf_params->get('return'))) ?>
<?php else: ?>
<?php echo input_hidden_tag('referer', 'dashboard') ?>
<?php endif ?>
Log in to <?php echo link_to('comment', sprintf('@sf_guard_signin_and_return?return=%s/%s?id=%d',
urlencode($sf_context->getModuleName(),
$sf_context->getActionName(),
$object->getId()))
?>