We started following the CakePHP Blog tutorial hosted on the website cakephp.org – http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html
At this point we’re stuck on the redirecting after submitting a form (i.e. function edit / add). This is how our code looks like:
public function edit($id = null) {
$this->Post->id = $id;
if ($this->request->is('get')) {
$this->request->data = $this->Post->read();
} else {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Your post has been updated.');
$this->redirect($this->referer());
} else {
$this->Session->setFlash('Unable to update your post.');
}
}
}
After commenting the line $this->redirect($this->referer()); the page is refering to his own… with the line added it’ll stay on a empty white page.
Example: http://www.drukwerkprijsvergelijk.nl/posts/
Please help this little kittens, we’re desperate.
you cannot use referer() on edit. thats because after the first POST the referer is the same page as you are on right now.
referer() can only be used for redirects if there was no form post on this page (delete for example or edit/add right after accessing the page).
but even with delete() you must be careful. coming from “view” would result the redirect to run into a redirect loop…
you can store the referer in the form as hidden field and use this to redirect back.