Reputation: 11
I have an action (view for example) in a controller that is called from multiple other actions in other controllers. How is the best way to create a "Back" button that will take me back to the page that got me here?
I've used named parameters like "back_controller" and "back_action" and that works fairly well but they get awkward when the page has a form that gets submitted. I have to be sure to pass those parameters as hidden fields or in the form url and then look for them after the form has been processed.
Is there some kind of stack or other solution that anyone else has come up with that handles this situation better? I see this problem in a lot of my projects and I've yet to come up with a good solution.
Upvotes: 1
Views: 153
Reputation: 72
I don't believe in back buttons. That is a feature that the browser does quite well and you would be better off having buttons always taking you to specific destinations rather than back.
If you must have a back button, you could create a history stack in the session. When a page loads you just push that page on the history (you will want to make sure you don't push the same page on the stack multiple times). You could create URL like /back who's sole job is to redirect the user to the last page they were on.
Upvotes: 1
Reputation: 656
I don't completely understand your question, but this may be helpful:
If you need to redirect to the referer page you can use:
$this->redirect($this->referer());
http://book.cakephp.org/view/425/redirect
Upvotes: 1