Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
yii框架表单属性未保存在数据库中_Yii - Fatal编程技术网

yii框架表单属性未保存在数据库中

yii框架表单属性未保存在数据库中,yii,Yii,我正试图保存表单中的数据。yii框架表单属性未保存在数据库中 以下是我的控制器代码: class ProfileController extends Controller { public function actionSave() { if (isset($_POST['Patients'])) { $patients = new Patients; $patients->name = $_POST['Patients']['name'];

我正试图保存表单中的数据。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());
       }
}

它没有保存在数据库中。上面的代码有什么问题?

它不会保存在数据库中。通常,问题与验证规则有关

仅为了调试,请尝试使用save(false)


如果模型已保存,则有选择地检查应用于模型的规则。

var_dump($patients->getErrors());显示了什么?它应该保存,因为它打印了save,但数据库中没有任何内容。我发布了一个asnwer。。
//$valid = $patients->validate();
$patients->save(false);