更新MULTI-MODEL失败的控制器/哪里有错误?

时间:2017-10-15 12:41:30

标签: yii2-advanced-app

控制器中的以下代码似乎有错误,这会避免像这样的功能

  1. 未输入条件
  2. 无法更新。记录未获更新
  3. 这两个模型的var_dump似乎没问题。属性按预期构成。任何想法,我做错了什么?

    这是控制器的代码

    
    
        public function actionUpdate($id) {
            try {
                $model = new Bewerber();
                $behavior = new \common\wsl_components\Wsl_Blameable_Behavior();
                $aktualisiert_von = $behavior->get_User_Person_Id();
                if (Yii::$app->request->post('_asnew') != '1') {
                    $model = $this->findModel($id);
                }
                $model_person = Person::findOne($model->id_person);
                if (!$model || !$model_person) {
                    throw new NotFoundHttpException("The user has no profile.");
                }
                $model->aktualisiert_von = $aktualisiert_von;
                $model_person->aktualisiert_von = $aktualisiert_von;
                $model->scenario = 'update';
                $model_person->scenario = 'update';
                if (Model::loadMultiple([$model, $model_person], Yii::$app->request->post())) {
                    $isValid = $model->validate();
                    var_dump($model->getErrors());
                    $isValid = $model_person->validate() && $isValid;
                    if ($isValid) {
                        $model->saveAll(false);
                        $model_person->saveAll(false);
                    }
                    $model->avatar = UploadedFile::getInstances($model, 'avatar');
                    if ($model->upload()) {
                        return $this->redirect(['view', 'id' => $model->id]);
                    }
                    return $this->redirect(['view', 'id' => $model->id]);
                } else {
                    return $this->render('update', [
                                'model' => $model,
                                'model_person'
                    ]);
                }
            } catch (\Exception $error) { //fange den schweren MySQL-Fehler ab
                $go_back = "bewerber";
                \common\wsl_components\error_handling::error($error, $go_back);
            }
        }
    
    
    

    条件:

     if (Model::loadMultiple([$model, $model_person], Yii::$app->request->post()))
    

    将是假的。任何想法,为什么?

0 个答案:

没有答案