【问题标题】:Delete link in baked views (index.ctp ) takes me to view.ctp instead of actually deleting烘焙视图 (index.ctp) 中的删除链接将我带到 view.ctp 而不是实际删除
【发布时间】: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


【解决方案1】:

我认为您应该传递将在 delete() 中删除的元素的 id,而不是单独指定元素的 id 来删除该元素

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多