Fullybaked-logo

fullybaked | davebaker

I'm a developer living in the UK and when I'm not spending time with my wife and our 2 wonderful little boys, I love hacking around with code

I'm passionate about technology, web development, gaming and fencing

31 January 2013

Redirect to where you came from in CakePHP

Just a little tip this time.

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