public function actionAjout2() { $model = new Inventorier(); if ($model->load(Yii::$app->request->post())) { $model2 = Inventorier::findOne($model->codebien); if (($model2 = Inventorier::findOne($model->codebien)) !== null) { if ($model2->comptage1 == '1' && $model2->comptage2 != '1') { $model2->comptage1 = '1'; $model2->comptage2 = '1'; $model2->anneeinv = date('Y'); $model2->bureau = $model->bureau; $model2->save(); \Yii::$app->getSession()->setFlash('success', 'Ajout avec succée.'); } } if (($model2 = Inventorier::findOne($model->codebien)) == null) { $model->comptage2 = '1'; $model->anneeinv = date('Y'); $model->save(); \Yii::$app->getSession()->setFlash('success', 'Ajout avec succée.'); } } return $this->render('ajout2', ['model' => $model]); }