-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Session] "getFlashBag" interfacing issue #11279
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
Comments
Duplicate of #10036 #5568. See @Drak's explanation here: #5568 (comment) |
Correct, but they are closed while it's still an issue. Possible solution? Create a FlashAwareSessionInterface that extends the SessionInterface but also has the getFlashBag for example. Edit: getBag('flashes') isn't 100% safe either. |
@fabpot you might possibly be interested, I've solved my problem like this: services:
session.flash_bag:
class: Symfony\Component\HttpFoundation\Session\FlashBagInterface
factory_service: session
factory_method: getFlashBag This has the following benefits:
It might not really go well with: #11315 because it's an interface typehint. But that should be fixable. This change should not have any BC issues, |
Closing this issue as it seems like it's not a priority to fix as a work-around is available. |
it looks like this is still an issue |
When you want the FlashBag to set a message, you'd like to do getFlashBag on the session. However, you can only achieve this by type hinting an injection on the Session\Session object. The Session\SessionInterface doesn't contain the "getFlashBag" method thus you can't use the Request::getSession();
If you do want to get the flash bag from it, you can try "getSession()->getBag('flash bag name')". However, that doesn't guarantee that you get the flash bag that was inserted because you don't know the name.
It's a minor inconvenience that has multiple custom solutions, but I've seen this issue come around a couple of times already in "#symfony".
The text was updated successfully, but these errors were encountered: