Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silex: Redirect with Flash Data

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?

Update

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.

like image 724
Mike Rockétt Avatar asked Sep 30 '13 14:09

Mike Rockétt


1 Answers

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 %}
like image 135
a4c8b Avatar answered Oct 04 '22 04:10

a4c8b