Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Symfony2 Redirect with POST data

I am implementing a payment gateway in my e-commerce application. On success/failure, it returns a JSON response on a given URL(for both success and failure). Depending on the state, I have to redirect it to success and failure URLs with POST data. I need two different URLs(success & failure) for analytic reasons.

My project is on Symfony 2.0

Now I know Symfony has a way to redirect.

$this->redirect($this->generateUrl('pg_success'));

But I cannot send POST data this way.

Also, there is a way to call another action using forward and send arguments

$this->forward('DemoBundle:Checkout:pgsuccess', $_POST);

But this does not change the URL in the address bar.

Is there a way to perform a URL redirect through which I can send arguments? Or some similar solution?

like image 811
sagarkalra Avatar asked Mar 16 '15 09:03

sagarkalra


1 Answers

It's not possible to redirect with POST data. You have following options to solve your problem:

  1. Redirect with GET parameters.

    $this->redirect($this->generateUrl('pg_success', $_POST));

  2. Use forward with arguments.

    $this->forward('DemoBundle:Checkout:pgsuccess', $_POST);

http://symfony.com/doc/current/book/controller.html#forwarding-to-another-controller

  1. Simply use session to pass data to the redirect target.

Before redirect:

$session = $this->getRequest()->getSession();
$session->set('data' => $_POST);

After redirect:

$session = $this->getRequest()->getSession();
$data = $session->get('data');
like image 174
Mikhail Prosalov Avatar answered Oct 28 '22 10:10

Mikhail Prosalov