我在CakePHP 2.0.0中有一个已烘焙的应用程序,并且视图中已烘焙的index.ctp(posts /)中的链接正在向我发送(posts / view / id,只有我可以删除帖子),而不是实际删除元素并闪烁消息“删除后”。 那是为什么?
以下是我在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']));
以下是Controller / PostsController.php中的烘焙函数delete:
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'));
}
我必须在CakePHP 2.2.3中测试相同的代码,并按预期工作: 它删除元素并闪烁消息“Post deleted”。
答案 0 :(得分:1)
我认为你应该传递将在delete()中删除的元素的id,而不是单独指定元素的id以删除该元素