我在 CakePHP 2.0.0 中有一个烘焙应用程序,并且在视图中烘焙 index.ctp (posts/) 中的链接正在发送我查看(posts/view/id 并且只有在那里我可以删除 Post),而不是实际上删除元素并闪烁消息“已删除”。这是为什么?
这是我在 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 中的烘焙函数删除:
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 中测试了相同的代码,它按预期工作:它删除了元素并闪烁消息“删除后”。