class Model extends AppModel{
public function deleteSomething(){
if (empty($this->id)) {
return false;
}
$this->read();
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->begin($this);
if (! $this->delete($this->id, true)) {
$db->rollback($this);
return false;
}
return $db->commit($this);
}
由于某种原因,这不会删除?我调试了id,这是正确的。 有任何想法吗?我错过了什么吗? }
答案 0 :(得分:2)
我看不到任何提交功能。我认为应该是:
if (! $this->delete($this->id, true)) {
$db->rollback($this);
return false;
}
$db->commit($this);
return true;
答案 1 :(得分:0)
public function delete()
{
$this->layout = 'iphone_gps';
$this->set('title_for_layout','Iphone GPS, LLC : Companies');
$this->Companies = $this->request->data;
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
foreach($this->Companies as $ids){
$this->Companie->deleteAll(array('Companie.company_id' => $ids));
}
$this->Session->setFlash($this->deleted);
$this->redirect('index');
}
在控制器中制作一个删除功能... 然后在index.ctp页面
中接下来echo "<br>".$this->Form->input('Delete',array('class' => 'youreclass','style' => 'display:block;width:100px;','onclick'=>"return confirm('Are you sure for delete data?')",array('type'=>'hidden')));