2013-05-03 55 views
0

我試圖軟刪除一條記錄,但是當我更新記錄時,我也得到了6條新的空記錄。這裏是我的編輯代碼CakePHP:編輯記錄還增加了新記錄

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

我也試過 $ this-> Store-> id = $ id; $ this-> Store-> saveField('status',0); 但結果沒有任何區別 – user612703 2013-05-03 23:23:39

+0

@nathan,我正在嘗試不同的技巧,我可以在互聯網上找到它的工作,所以它是其中之一,當我在這裏複製代碼時,它就在那裏。 使用這個結果沒有什麼區別。我現在要從這裏刪除它 – user612703 2013-05-03 23:26:18

+0

您可以添加Store模型的代碼和數據庫表的定義嗎? – thaJeztah 2013-05-06 21:16:54

回答

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/"); 
} 

}

+0

它會在數據庫中添加空記錄 – user612703 2013-05-04 13:29:04

+1

你會描述你的表結構。 ? – liyakat 2013-05-05 16:37:19

0

集ID爲Store模式,然後使用saveField。

public function del($store_id) 
{ 
    $this->Store->id = $store_id; 
    $this->Store->saveField('status', 0); 
    $this->redirect('/stores/'); 
} 
+0

試過了,它不起作用。 – user612703 2013-05-04 13:28:18