Skip to content
Closed
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion security/access_denied_handler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ unauthenticated user tries to access a protected resource::
public function start(Request $request, AuthenticationException $authException = null): RedirectResponse
{
// add a custom flash message and redirect to the login page
$request->getSession()->getFlashBag()->add('note', 'You have to login in order to access this page.');
$session = $request->getSession();
if ($session instanceof FlashBagAwareSessionInterface) {
$session->getFlashBag()->add('note', 'You have to login in order to access this page.');
}

return new RedirectResponse($this->urlGenerator->generate('security_login'));
}
Expand Down
5 changes: 5 additions & 0 deletions session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ if you type-hint an argument with :class:`Symfony\\Component\\HttpFoundation\\Re
// the second argument is the value returned when the attribute doesn't exist
$filters = $session->get('filters', []);

// when the session is flashBag aware, you can add a flash message
if ($session instanceof FlashBagAwareSessionInterface) {
$session->getFlashBag()->add('note', 'This is a flash message.');
}

// ...
}
}
Expand Down