Redirect and setAction, how are they different?

Hi all,

I am a bit confused about the difference between redirect() and setAction()?

I guess the biggest difference is I can pass variable between actions with setAction().

Do you have any practical cases that you see the big difference between them?

Thank you.

redirect return response to browser and tell it, that it should get new address from server (new request).
setAction work in first request and continue working in other controller method (action). Check for address bar in your browser, you should notice the different.

Redirect() sends a HTTP 302 response to the browser with the redirect URL, which makes the browser (and the serverr) dump the current HTTP request and start a new one. This is a very heavyweight action.
setAction() simply runs a different action on the same controller, almost like the original action function calling the second action function, but with more CakePHP bookkeeping. Compared to redirect(), the browser is none the wiser. In fact, the original URL with the original action (with default routing) will remain in the browser.