Skip to content

Mentioned the TargetPathTrait utility #9112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions security/form_login.rst
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,24 @@ are now fully customized:
<input type="hidden" name="back_to" value="<?php echo $view['router']->path('forgot_password') ?>" />
<input type="submit" name="login" />
</form>

Redirecting to the Last Accessed Page with ``TargetPathTrait``
--------------------------------------------------------------

The last request URI is stored in a session variable named
``_security.<your providerKey>.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.