How to go back to the previous page in CakePHP


In your controller use this to go back to the previous page:

$this->redirect($this->referer());

3 Responses to “How to go back to the previous page in CakePHP”

  1. Hi,
    Actually, it’s a good habit to use the referer function’s parameters.
    The code would thus be something like:
    $this->redirect($this->referer(array(‘action’=>’index’), true));

    Pierre 😉

  2. Navigate to a page that has a form. $this->referer points to previous page
    However fill in and submit the form. $this->referer points to the current page

    Any ideas on how to preserve the first $this->referer so that you are not redirected to the same page you are currently on?

Leave a comment