8.4.2 What's the alternative to redirect?
Someone suggested to use URL::to() instead, but it simply returns the URL, what's the actual redirect alternative? How to use the URL::to to redirect?
$processor = $controller->getFormProcessor(); $r = Redirect::to($url); $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID); return $processor->deliverResponse($entry, ProcessorInterface::REQUEST_TYPE_ADD, $r);
I don't see how this is a substitute for the redirect because I don't return anything, I simply need to go to a page, not necessarily within an action.
Anyway, if you look deeper you will see that doing Redirect::to() creates a redirect response with a 302 code (redirected but not permanent)
Redirect::page() allows you to specify your own redirect code instead of 302.
That object you get is an instance of Symfony\Component\HttpFoundation\RedirectResponse which extends Symfony\Component\HttpFoundation\Response.
That, in turn, can be triggered by the send() function.
so you can do
$r = Redirect::to('/your/path'); $r->send(); exit;
What's more, if you look at the deprecated Redirect() function you will see
Which basically does exactly what I told you. It takes your arguments and use the proper Response instance instead of the old deprecated code.
All of this is slightly below the surface in the core code, you just have to look.
Thank you for your help.
The comment was to replace
for URL::to. I could not find that anywhere in the documentation. I guess he made a mistake, it should have been Redirect::to.