2013-05-03 85 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