On cakephp 5.1
I am trying to redirect to the previous page, but it keeps on redirecting to the main/parent page.
When checking $this->referer(), it returns ‘/’
The docs says return $this->redirect($this->referer());
Where are you doing this debug()?
After you clicked on a link and ended up on a different action?
The referer is to be read after the link has been clicked.
And based on that it will then show where it came from.
The docs and your first example is about controller redirecting, and a different thing then you are displaying here with templates.
The referer redirect is commonly used on PRG pattern, so after postLinks() to edit/delete of an entry, or after access to a specific action is not allowed etc.
Not sure what you are doing there in the template with it.
Here usually one uses query strings to persist certain flows.
For more complex controller based scenarios, e.g. on default edit workflows, there is also
and Tools plugin enhanced redirecting.
So: None of this is clear based on the wage input from you so far.
So as mentioned by someone before, you should always post all the relevant data on an issue for people to get useful feedback.