Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionCreate()
- {
- $model = new Order();
- if ($model->load(Yii::$app->request->post())) {
- $transaction = Yii::$app->db->beginTransaction();
- try {
- $success = $model->save();
- if ($success) {
- $model = $this->findModel($model->id);
- $model->orderItems = Yii::$app->request->post('OrderItem', []);
- $success = $model->save();
- if ($success) {
- $transaction->commit();
- return $this->redirect(['view', 'id' => $model->id]);
- }
- }
- $transaction->rollBack();
- } catch (\Exception $ecx) {
- $transaction->rollBack();
- throw $ecx;
- }
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement