Skip to content

How to actually use peek / peekAll with flashes #20198

Closed
@pauljura

Description

@pauljura

The documentation here: https://symfony.com/doc/current/session.html#flash-messages has a single line that says you can use peek() to check for messages while leaving them in the bag, but there is no example of the actual syntax one would need to use in order to achieve this.

The documentation only mentions app.flashes so naturally one would try app.flashes.peek or app.flashes().peek() or maybe app.peek() or app.peek.flashes or even just peek() by itself, or some other variation, but none of these work.

The only way to use peek() is with app.session.flashbag.peek($type) and the $type argument is mandatory, e.g. app.session.flashbag.peek('error'). It's worth noting that app.flashes can take an array, e.g. app.flashes(['error', 'warning']) but peek cannot.

There is also no mention of the very useful peekAll method on that page, nor anywhere else in the Symfony docs. This is used to check for messages of any type, and the syntax is: app.session.flashbag.peekAll

If this could be added, that would be great. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIdeal for your first contribution! (some Symfony experience may be required)hasPRA Pull Request has already been submitted for this issue.help wantedIssues and PRs which are looking for volunteers to complete them.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions