Exemplo n.º 1
0
 /**
  * Creates a new Benhnhan model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Benhnhan();
     $connection = \Yii::$app->db;
     $transaction = $connection->beginTransaction();
     try {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             $model_1 = new Hoso();
             $model_1->maBN = $model->id;
             $model_1->load(Yii::$app->request->post());
             $model_1->save();
             $transaction->commit();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }