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());

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: