我想在cakephp中顯示數據庫錯誤。如何向用戶顯示「sql error」消息。這是我的代碼。在這段代碼中,我收到了數據庫錯誤。但我想向用戶顯示正確的消息而不是數據庫錯誤。Cakephp 2.5.4:數據庫錯誤錯誤:SQLSTATE [23000]:完整性約束違規:1062重複條目
public function edit_mothertongue(){
$motherTongue=array();
if($this->request->is('post')){
foreach ($this->request->data as $key => $value) {
$motherTongue[$key]=$value;
}
if(!empty($motherTongue)){
App::import('Model','MotherTongue');
$this->MotherTongue=new MotherTongue();
try{
if($this->MotherTongue->save($motherTongue)){
echo "Record saved";
}else{
echo "Record not saved";
}
}
catch(Exception $e){
echo $e->getMessage(); // I want to display error message of sql.
}
}
}
}
如果我想通過ajax顯示錯誤信息,那我該怎麼辦?請回答這個問題,我將不勝感激。 – 2014-09-21 13:50:26