tags:

views:

641

answers:

2

I want to know the difference between :

$this->forward("module", "action");

And

$this->redirect("module/action");

My first guess is that one implies a new request while the other one not, but I'm not sure.

A: 

Reading the documentation is always a good start.

Milen A. Radev
I don't downvote because I usually use RTFM a lot. But comparing the page you gave me and Peter's anwser will show you why I asked this question.
e-satis
Well the sad part about all of this is that I ripped my entire answer from the symfony documentation. :)
Peter D
Well, being fair would be giving +1 at Milen then. I don't think he deserves -3 for calling me lazy.
e-satis
And after fighting all this day with symfony, I'm probably lazy enougt.
e-satis
+2  A: 

In some cases, the action execution ends by requesting a new action execution. For instance, an action handling a form submission in a POST request usually redirects to another action after updating the database. Another example is an action alias: the index action is often a way to display a list, and actually forwards to a list action.

The action class provides two methods to execute another action:

If the action forwards the call to another action:

$this->forward('otherModule', 'index');

If the action results in a web redirection:

$this->redirect('otherModule/index');
$this->redirect('http://www.google.com/');

The choice between a redirect or a forward is sometimes tricky. To choose the best solution, keep in mind that a forward is internal to the application and transparent to the user. As far as the user is concerned, the displayed URL is the same as the one requested. In contrast, a redirect is a message to the user's browser, involving a new request from it and a change in the final resulting URL.

If the action is called from a submitted form with method="post", you should always do a redirect. The main advantage is that if the user refreshes the resulting page, the form will not be submitted again; in addition, the back button works as expected by displaying the form and not an alert asking the user if he wants to resubmit a POST request.

Peter D
Thanks, especially about the last point.
e-satis