/** * Creates a new Fields model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Fields(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionAdd($id) { $forms = $this->findModel($id); $fields = new Fields(); if ($fields->load(Yii::$app->request->post())) { foreach ($_POST['Fields'] as $field) { $fields->attributes = $field; $fields->form_id = $id; if ($fields->save()) { $fields = new Fields(); } } return $this->redirect(['index']); } else { return $this->render('add_fields', ['model' => $fields, 'forms' => $forms]); } }