0

我正在尝试软删除记录,但是当我更新记录时,我还会得到 6 条新的空记录。这是我的编辑代码

public function del($id = null){
    $dt = $this->Store->findById($id);

    $dt["Store"]["status"] = 0;

    if($this->Store->save($dt)){
        $this->Session->setFlash("Your Store has been Deleted");
        $this->redirect("/stores/");
    }
}
4

2 回答 2

0

为 Store 模型设置 id,然后使用 saveField。

public function del($store_id)
{
    $this->Store->id = $store_id;
    $this->Store->saveField('status', 0);
    $this->redirect('/stores/');
}
于 2013-05-04T11:05:59.660 回答
0

正如您在问题中描述的那样,更新功能肯定会帮助您

public function del($id = null){
$dt = $this->Store->findById($id);

$dt["Store"]["id"] = $dt['Store']['id'];
// or

   $dt["Store"]["id"] = $id // not empty every time.

   $dt["Store"]["status"] = 0;

if($this->Store->save($dt)){
    $this->Session->setFlash("Your Store has been Deleted");
    $this->redirect("/stores/");
}

}

于 2013-05-04T04:03:18.343 回答