diff --git a/security/form_login.rst b/security/form_login.rst index 900444aeef6..211d570be09 100644 --- a/security/form_login.rst +++ b/security/form_login.rst @@ -430,3 +430,24 @@ are now fully customized: + +Redirecting to the Last Accessed Page with ``TargetPathTrait`` +-------------------------------------------------------------- + +The last request URI is stored in a session variable named +``_security..target_path`` (e.g. ``_security.main.target_path`` +if the name of your firewall is ``main``). Most of the times you don't have to +deal with this low level session variable. However, if you ever need to get or +remove this variable, it's better to use the +:class:`Symfony\\Component\\Security\\Http\\Util\\TargetPathTrait` utility:: + + // ... + use Symfony\Component\Security\Http\Util\TargetPathTrait; + + $targetPath = $this->getTargetPath($request->getSession(), $providerKey); + + // equivalent to: + // $targetPath = $request->getSession()->get('_security.'.$providerKey.'.target_path'); + +.. versionadded:: 3.1 + The ``TargetPathTrait`` was introduced in Symfony 3.1.