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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭