I need to redirect one page to another with a message in Silex. Hopefully there's a Laravelesque way of doing it, but I highly doubt it:
$app->redirect('/here', 301)->with('message', 'text');
I'd then want to display the message in my template:
{{ message }}
If not, is there another way?
I see there's a getFlashBag
method in Symfony - is that what I'm supposed to use? Specifically, I am using the Bolt Content Management system.
Yes, FlashBag is the right way. Set a flash message in your controller (you can add multiple messages):
$app['session']->getFlashBag()->add('message', 'text');
$app->redirect('/here', 301)
And print it in the template:
{% for message in app.session.getFlashBag.get('message') %}
{{ message }}
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With