Redirect to where you came from in CakePHP

 Jan 31, 2013

Sometimes an action or link needs to take the user back to where they came from each time rather than to an explicit location. When this happens CakePHP has a handy short cut that can be used from the controller or view

Controller:

<?php
public function action() {
    $this->redirect(Controller::referer());
}

View:

<?php
echo $this->Html->link('Back', Controller::referer());

See the API here