Reputation: 575
I am writing a Symfony2 controller. My controller deletes a user and then displays a success or failure message. This is working and the response looks like:
return $app['twig']->render('index.twig', array('list' => $list,'msg' => $msg));
There is one issue. The website lands on index/{username}/
. I would like the website to instead land on index/
and display the message there. I am able to redirect with the following response:
return new RedirectResponse('/index/users/');
The question is how do I bundle together both responses, so I redirect to index/
and also display the message there?
Upvotes: 1
Views: 681
Reputation: 584
You cannot bundle 2 different responses together... the controller MUST return a Response object of some sort... and only one...
you best solution would be to take advantage of flash messages... You can store your message in the flashbag (which is basically the session) then view it on the "index" after you have been redirected...they are called flash because they disappear after the first read....
you can also forward the request to another controller internally without actually sending a 301 to the browser.. ... that might be another solution you can play around with ...
Upvotes: 1