【问题标题】:CakePHP Error: The requested address was not found on this serverCakePHP 错误:在此服务器上找不到请求的地址
【发布时间】:2014-07-29 22:08:33
【问题描述】:

我有一个操作从用户那里获取id 并删除与之相关的项目;请求是这样的:

/managers/delete_item/5 但这会发生错误:

错误:在此服务器上找不到请求的地址 /managers/delete_item/5

这是控制器中的delete_item

function delete_item($id = null)
{
    $this->item->id = $id;
    $this->item->status = 0;
    if ($this->data) {
        if ($this->item->save($this->data)) {
            $this->Session->setFlash('Removed', 'default', array('class' => 'success-msg'));
            $this->redirect(array('controller' => 'managers', 'action' => 'discount'));
        } else {
            $this->Session->setFlash('ERR', 'default', array('class' => 'error-msg'));
        }
    } else {
        $this->data = $this->item->read();
    }
}

但是,我的控制器中有一些类似的操作,它们执行删除、编辑等操作,但不会发生错误。

请帮忙。

【问题讨论】:

  • 使用以下步骤检查确切的错误消息 - 1. application->config->core.php : Configure::write('debug', 2); 2. 刷新页面 3. 你会得到错误堆栈的确切原因。在这里分享完整的堆栈,以便我可以帮助您...请另外提及您正在使用的 cakephp 版本,是 2.0+ 还是
  • 调试器未报告与此问题相关的错误。版本是 1.2.1.8004
  • 使用$this->item->status=0 我正在尝试更改数据库中的status 字段然后保存它们。这有什么问题?
  • @user3642119 对于此类事件,您应该使用saveField()。请参阅book.cakephp.org/1.2/en/The-Manual/Developing-with-CakePHP/…(向下滚动一点查看saveField() 部分)。

标签: php cakephp


【解决方案1】:

您似乎正在为该操作寻找saveField() 方法。这只会更新模型中的单个字段。这应该可以解决问题:

function delete_item($id = null) {
    $this->Item->id = $id;

    // Try to update the status
    if ($this->Item->saveField('status', 0)) {
        $this->Session->setFlash('Removed', 'default', array('class' => 'success-msg'));
    } else {
        $this->Session->setFlash('ERR', 'default', array('class' => 'error-msg'));
    }

    // Always redirect, regardless of the outcome (to make sure no view is needed)
    $this->redirect(array('controller' => 'managers', 'action' => 'discount'));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    相关资源
    最近更新 更多