我正在尝试软删除记录,但是当我更新记录时,我还会获得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/");
}
}
答案 0 :(得分: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/");
}
}
答案 1 :(得分:0)
设置商店模型的ID,然后使用saveField。
public function del($store_id)
{
$this->Store->id = $store_id;
$this->Store->saveField('status', 0);
$this->redirect('/stores/');
}