$this->forwardToReferringRequest(); => go back to previous url?

Hello everybody,

let’s say I’m at the following URL right now:

…/order/index

In this template I can change the address:

<f:form action="update" controller="address" objectName="address" object="{address}">
...
</f:form>

In my updateAction I’m using:

$this->forwardToReferringRequest();

so that I can get back to my …/order/index after the update. In some sense, it is working => the page content will be …/order/index again. However, the URL in the browser still shows …/address/update

I think, I have to use a kind of

$this->redirect(!)ToReferringRequest();

However, this function does not exist. Does anyone have any advice for me on the best way to approach this? Thanks for your help!

I found this workaround:

$this->redirectToUri($this->request->getHttpRequest()->getServerParams()['HTTP_REFERER']);

My feeling tells me this is not the cleanest way to go?!

You can use $this->redirectToRequest($this->request->getReferringRequest()) .
Mind you though, that this effectively lets your update action create arbitrary work flows, i.e. the user ending up at different pages depending on where he came from. This may be wanted, but in a lot of cases this is unwanted - so be aware of that :slight_smile:

Oh perfect - this looks like much better code - and the best: it works. Thanks a lot for your help! :slight_smile:

If you know which action you want to go back to, you might as well code as

$this->redirect('index');