Alex Rivera | Logout

Symfony2: Redirecting to last route and flash a message?

Asked 2012-08-09T21:17:04.840
48

I'm having a small problem when trying to flash a message and redirect the user back to the previous page in Symfony 2.

I have a very simple CRUD. When new, or edit, i want to flash a message if something goes wrong in the respective create/update methods:

  1. User --GET--> new
  2. new --POST--> create (fails)
  3. --REDIRECT--> new (with flash message)

I'm doing the following:

  $this->container->get('session')->setFlash('error', 'myerror');
  $referer = $this->getRequest()->headers->get('referer');   
  return new RedirectResponse($referer);

However, it's not redirecting to the correct referrer! Even though the value of referrer is correct (eg.: http://localhost/demo/2/edit/) It redirects to the index. Why?

Edit
Report

1 Answer

0

seems like you need to have a payload for your redirect to point to. it seems like obscure concept code to me. I would also advise you to make sure your configuration files point to the correct redirect code snippet. Check your server access file to make sure it has redirects enabled also.

answered 2012-08-10T06:41:01.707

Your Answer