コード例 #1
0
 /**
  * Creates a new Transfer model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Transfer(['branch_id' => 1]);
     $api = new ApiTransfer(['modelClass' => Transfer::className()]);
     //load gr list
     $gmovement = new \yii\data\ArrayDataProvider();
     if ($model->load(Yii::$app->request->post())) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $data = $model->attributes;
             $data['details'] = Yii::$app->request->post('TransferDtl', []);
             $model = $api->create($data, $model);
             if (!$model->hasErrors()) {
                 $transaction->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             } else {
                 $transaction->rollBack();
             }
         } catch (\Exception $e) {
             $transaction->rollBack();
             throw $e;
         }
     }
     return $this->render('create', ['model' => $model, 'details' => $model->transferDtls, 'gmovement' => $gmovement]);
 }