1
votes

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".

1
What does the baked view (specifically the delete link) look like? I would suggest updating to the latest 2.0.x if you can as that should be a safe update and might fix the problem. I do remember having quite a few problems when 2.0 came out but it has become quite stable since then.David Gallagher
Im pretty certain you can pass delete() an $idDavid Yell

1 Answers

1
votes

I think you should pass the id of the element which will be deleted in delete() instead of specifying id of element seperately to delete that element