On the login page, we can use the stored url to redirect the user
to their requested page after login. If the user mis-typed their
password, we must extend the redirect with extendRedirect()
to keep it for the next request. By default, urls are only kept for one
request. If you need them for more than one, you can do setExpirationHops(4 /*requests*/)
to change the number of requests to keep the url.
After a success, you can either use the builtin redirect functions
redirect(array('code' => 303)) or redirectAndExit();
If you would rather process the redirect yourself, you can use getRedirect()
to retrieve the url.
You do not have to check if a redirect exists with hasRedirect()
although it is recommended.
<?php
class LoginController extends Zend_Controller_Action
{
public function loginAction()
{
$flashRedirector = $this->getHelper('FlashRedirector');
// Login [...]
if (!$auth) {
// User failed auth, extend the redirect
// and reshow login form
if ($flashRedirector->hasRedirect()) {
$flashRedirector->extendRedirect();
}
} else {
// Authentication sucess!
// Redirect to previous requested page
if ($flashRedirector->hasRedirect()) {
$flashRedirector->redirect();
// $flashRedirector->redirectAndExit();
}
}
}
}