Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. public function actionCreate()
  2. {
  3.     $model = new Order();
  4.  
  5.     if ($model->load(Yii::$app->request->post())) {
  6.     $transaction = Yii::$app->db->beginTransaction();
  7.     try {
  8.         $success = $model->save();
  9.         if ($success) {
  10.             $model = $this->findModel($model->id);
  11.             $model->orderItems = Yii::$app->request->post('OrderItem', []);
  12.             $success = $model->save();
  13.             if ($success) {
  14.                 $transaction->commit();
  15.                 return $this->redirect(['view', 'id' => $model->id]);
  16.             }
  17.         }
  18.         $transaction->rollBack();
  19.     } catch (\Exception $ecx) {
  20.         $transaction->rollBack();
  21.         throw $ecx;
  22.     }
  23.     } else {
  24.         return $this->render('create', [
  25.             'model' => $model,
  26.         ]);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement