doucang9673 2014-07-29 13:37
浏览 47
已采纳

CakePHP错误:在此服务器上找不到请求的地址

I have an action which gets the id from user and deletes the item related to; Requests are like this:

/managers/delete_item/5 But this occurs error:

Error: The requested address /managers/delete_item/5 was not found on this server

This is the delete_item in controller:

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();
    }
}

However i have some similar actions in my controller which doing such thing Deleting, Editing... and not occurs the error.

Please help.

  • 写回答

1条回答 默认 最新

  • dongmoyu0336 2014-07-29 14:08
    关注

    It appears you're looking for the saveField() method for this action. This just updates a single field in your model. This should do the trick:

    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'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考