I have a baked app in CakePHP 2.0.0 and the links in the baked index.ctp (posts/) in views , is sending me to view (posts/view/id and only there I can delete the Post), instead of actually deleting the element and flashing the message "Post deleted". Why is that?
Here is my baked link in View/Posts/index.ctp :
$this->Form->postLink(__('Delete'), array('action' => 'delete', $post['Post']['id']), null, __('Are you sure you want to delete %s?', $post['Post']['id']));
Here is the baked function delete in Controller/PostsController.php:
public function delete($id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->Post->id = $id;
if (!$this->Post->exists()) {
throw new NotFoundException(__('Invalid post'));
}
if ($this->Post->delete()) {
$this->Session->setFlash(__('Post deleted'));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Post was not deleted'));
$this->redirect(array('action' => 'index'));
}
I must day that I just tested the same code in CakePHP 2.2.3 and it worked as expected: It deletes the element and flashes the message "Post deleted".
delete()
an$id
– David Yell