Last active
August 29, 2015 14:27
-
-
Save hmic/1c6bc9d9fa1ed12724af to your computer and use it in GitHub Desktop.
CakePHP: Don't refer to the same page (again)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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