【发布时间】:2012-10-22 23:20:10
【问题描述】:
我在 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中的烘焙函数删除:
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 中测试了相同的代码,它按预期工作: 它删除元素并闪烁消息“已删除”。
【问题讨论】:
-
烘焙视图(特别是删除链接)是什么样的?如果可以的话,我建议更新到最新的 2.0.x,因为这应该是一个安全的更新并且可能会解决问题。我记得当 2.0 出来的时候有很多问题,但从那以后它变得相当稳定了。
-
我很确定你可以通过
delete()和$id
标签: cakephp hyperlink cakephp-2.0