2013-10-04 59 views
0

我想在我的表中使用yii模型插入記錄。它顯示沒有錯誤,但沒有記錄被添加。現在我想在保存在yii之前檢查sql查詢。有什麼辦法可以做到嗎?如何在保存之前檢查sql查詢yii

這是我的代碼的一部分。

$form = new BaseSysRegistration(); 
$form->attributes = $_POST['BaseSysRegistration']; 
$form->of_passport_number = $_POST['of_passport_number']; 
$form->password2 = $_POST['BaseSysRegistration']['password']; 
$form->email_addr = $_POST['BaseSysRegistration']['email_addr']; 
$form->save(); 

回答

0
$form = new BaseSysRegistration(); 
$form->attributes = $_POST['BaseSysRegistration']; 
$form->of_passport_number = $_POST['of_passport_number']; 
$form->password2 = $_POST['BaseSysRegistration']['password']; 
$form->email_addr = $_POST['BaseSysRegistration']['email_addr']; 

if ($form ->save(true)) { // Return if the model is saved. (With true validate the fields) 
    Yii::app()->user->setFlash('success', 'All correct'); 
    $this->redirect(array('index')); 
}else{ 
    Yii::app()->user->setFlash('error', 'Error'); 
    $this->redirect(array('update', 'model' => $form)); 
} 
+0

謝謝,我會試試看:0 – Enrico