Skip to content

Instantly share code, notes, and snippets.

@hmic
Last active August 29, 2015 14:27
Show Gist options
  • Save hmic/1c6bc9d9fa1ed12724af to your computer and use it in GitHub Desktop.
Save hmic/1c6bc9d9fa1ed12724af to your computer and use it in GitHub Desktop.
CakePHP: Don't refer to the same page (again)
class Appcontroler extends Controller {
public function referer($default = null, $local = false)
{
$referer = $this->request->session()->read('Session.referer');
if($default === null && $referer) {
return $referer;
}
return parent::referer($default, $local);
}
public function beforeFilter(Event $event)
{
$referer = $this->request->referer(true);
$here = $this->request->here;
if (strpos($here, $this->request->base) === 0) {
$here = substr($here, strlen($this->request->base));
if ($here[0] !== '/') {
$here = '/' . $here;
}
}
if($referer != $here) {
$this->request->session()->write('Session.referer', $referer);
}
return parent::beforeFilter($event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment