/** * Creates a new Booking model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Booking(); $bookingField = new BookingFields(); $data = Yii::$app->request->post(); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { if (isset($data['BookingFields']['fields'])) { $bookingField->fields = Json::encode($data['BookingFields']['fields']); $bookingField->booking_id = $model->id; $bookingField->save(); } return $this->redirect(['view', 'id' => $model->id]); } return $this->render('create', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } }
public function getFields() { return $this->hasMany(BookingFields::className(), ['booking_id' => 'id']); }