我试图从表单中保存数据。 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());
}
}
它不会保存在数据库中。上面的代码出了什么问题?
答案 0 :(得分:0)
它不会保存在DB中。通常,该问题与验证规则有关。
仅用于调试,请尝试使用save(false)
//$valid = $patients->validate();
$patients->save(false);
如果保存了模型,则有选择地检查应用于模型的规则。