diff --git a/book/security.rst b/book/security.rst index b63abe37d11..15b072952b4 100644 --- a/book/security.rst +++ b/book/security.rst @@ -449,16 +449,21 @@ Next, create the controller that will display the login form:: $error = $request->attributes->get( SecurityContextInterface::AUTHENTICATION_ERROR ); - } else { + } elseif (null !== $session && $session->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { $error = $session->get(SecurityContextInterface::AUTHENTICATION_ERROR); $session->remove(SecurityContextInterface::AUTHENTICATION_ERROR); + } else { + $error = ''; } + + // last username entered by the user + $lastUsername = (null === $session) ? '' : $session->get(SecurityContextInterface::LAST_USERNAME); return $this->render( 'AcmeSecurityBundle:Security:login.html.twig', array( // last username entered by the user - 'last_username' => $session->get(SecurityContextInterface::LAST_USERNAME), + 'last_username' => $lastUsername, 'error' => $error, ) );