2
我試圖保存表單中的數據。 yii框架表單屬性沒有被保存在數據庫中。yii框架表單屬性未保存在數據庫中
這裏是我的控制器代碼:
class ProfileController extends Controller {
public function actionSave() {
if (isset($_POST['Patients'])) {
$patients = new Patients;
$patients->name = $_POST['Patients']['name'];
$patients->mobile = $_POST['Patients']['mobile'];
$patients->email = $_POST['Patients']['email'];
$patients->password = $_POST['Patients']['password'];
$patients->dob = $_POST['Patients']['dob'];
$patients->weight = $_POST['Patients']['weight'];
$patients->height = $_POST['Patients']['height'];
$patients->activation_date = '0000-00-00';
$patients->credit = 0;
$patients->archive = 0;
$patients->balance = 0;
$patients->first_login = 0;
$patients->guide_status = 0;
$patients->passcode = '';
}
//echo $patients->save_personal_data();
$valid = $patients->validate();
if ($valid) {
$patients->save();
} else {
var_dump($patients->getErrors());
}
if ($patients->save()) {
echo 'saved';
} else {
var_dump($patients->getErrors());
}
}
它不是在數據庫中保存。上面的代碼有什麼問題?
var_dump($ patients-> getErrors());什麼顯示? – scaisEdge
它應該保存,因爲它打印保存但數據庫中沒有任何內容 –
我發佈了一個asnwer .. – scaisEdge