I followed the cakePHP Blog Tutorial and I have a logical error happened in the cakephp/posts/add
Routine
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html
I got the default cakephp/posts/add
Routine from the tutorial working just fine, but when I duplicate the routine and try to rename it to cakephp/apples/add
(Posts to Apples) it seems that $this->Apple->save($this->request->data)
and $this->redirect(array('action' => 'index'))
is not working it just refreshes me the page and doesn't redirect to the index view and doesn't save the record also.
public function add() {
if ($this->request->is('apple')) {
$this->Apple->create();
if ($this->Apple->save($this->request->data)) {
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Unable to add your post.'));
}
}
what would be the possible problem in this?
The problem lies at this line:
if ($this->request->is('apple')) {
You are checking for the type of request to determine if it is a form submission (usually POST), hence it should instead be
if ($this->request->is('post')) {