Return to the called page in CakePHP 3
<p>I have an action, /controller/edit, which can be clicked to from multiple locations (e.g. /controller/index and /controller/view).</p>

<p>Once the user has finished editing the record and clicks save, I want them to return to wherever they came from (/controller/index or /controller/view respectively).</p>

<p>At first I tried storing each page the user visits in their session (e.g. home > index > edit), and then redirecting to the second-to-last entry in that list - and that works fine right up until they open another tab. If, while they're editing the record they open another tab and go off somewhere else, their session variable keeps being built on (home > index > edit > help > help page), and when the time comes to redirect the second-to-last entry no longer contains the correct action.</p>

<p>How can my edit action /controller/edit, on save, redirect the user back to the referring page they came from to get there, independent of whatever the user has done in other tabs?</p>

<p>Edit: I can't use referrer after save because the process is this:</p>

<ol>
<li>User is on either /controller/index or /controller/view</li>
<li>User clicks into /controller/edit (referrer is /controller/index or /controller/view)</li>
<li>User makes changes to record and clicks save, which form submits to /controller/edit (referrer is /controller/edit)</li>
<li>I now want to redirect them to either /controller/index or /controller/view, but that is no longer in the referrer</li>
</ol>