2014-12-05 74 views

回答

0

如果沒有您編寫的實際代碼,它很難回答,但這裏是基於您分享的內容少的通用答案。更多細節在蛋糕的網站上找到的this link

假設你從控制器

if ($this->ProductCategory->deleteAll(array('conditions' => array('id' => $someId)) { 
    // do something else - set success flash message 
    $this->Session->setFlash('Something good.', 'default', array(), 'good'); 
} else { 
    // error occurred 
    $this->Session->setFlash('Something bad.', 'default', array(), 'bad'); 
} 

您也可以級聯由以上delete語句設置一個額外的參數刪除到子表調用此 - 這是也發現在同一鏈接。如果你要級聯然後刪除該語句將類似於下面的 - 注意TRUE作爲第二個參數

if ($this->ProductCategory->deleteAll(array('conditions' => array('id' => $someId), true) { 
    // do something else - set success flash message 
    $this->Session->setFlash('Successfully deleted the Product Category', 'default'); 
} else { 
    // error occurred 
    $this->Session->setFlash('Cannot delete Product Category. Some Products are still using this Category.', 'default'); 
} 

此外,我建議你不要在數據庫中執行的完整性約束 - 沒有什麼錯,但它會讓你的邏輯更加複雜。

相關問題