views:

211

answers:

4

I an redirection (in some cases) from a controller to the error controller, action 'not-logged-in' using the redirector helper. My problem is the following: I want to pass an argument in the $_POST array (an URL from where the redirection happened) so the user will be able to return to that page after performing a login.

How can i place data in the $_POST array while using redirect helper?

Thank you ahead.

A: 

Not possible without some socket or Curl jiggery pokery.

Why not try using $_SESSION array in the same way?

Does it really matter if the user can see the redirection url in the address bar? i doubt they will care and i see it a few times on some top sites.

Question Mark
A: 

I'm pretty sure that you can't send POST when redirecting a person to another page. But maybe you can, and if so, I hope somebody proves me wrong here.

I'm not sure how you'd do what you want using Zend Framework, but I would suggest two ways how to do it in general. You can either send a GET variable, or use a session variable to store a back-URL.

Igor Zinov'yev
+1  A: 

Passing control to the login page just feels more like a _forward than a _redirect, like it all belongs under the one action. Especially since you're coming right back.

_forward($action, $controller = null, $module = null, array $params = null)

Then, you can pass your originating location in $params as you'd like.

Derek Illchuk
+3  A: 

When you use the redirector with an internal redirect (ie. goToRoute) the paramters are passed along with it. Thus if you add your refferrer to the the request before you actually redirect:

// Assuming $request is a Zend_Controller_Request
$request->setParam('ref', $referrer);
// then use the redirector

then that variable will be passed along with the request upon redirect. So then you would need to check for/grab that variable from the request in the action youve redirected to and then set it as a hidden field in the form. Then when your form posts to your login action you can check again for a ref variable and on successful login redirect to that location.

Now if i were you i would not actually use the referral as the url but a serialized or json encoded array of the previous request's parameters. that way you can use goToRoute in this second instance as well.

Ofcourse if the redirection came form some sort of post action that contained sensitive data you wouldnt want to do this. In that case you would want to use the session as has been previously suggested.

Above all the best advice i can give is to look at the code of Zend_Controller_Router_Rewrite and Zend_Controller_Action_Helper_Redirector.

prodigitalson