/** * Creates a new SourcesSettings model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new SourcesSettings(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Updates an existing RssSources model. * If update is successful, the browser will be redirected to the 'view' page. * * @param integer $id * * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $postData = Yii::$app->request->post(); if ($model->load($postData) && $model->save()) { SourcesSettings::deleteAll(['source_id' => $model->source_id]); if (isset($postData['RssSources']['settings'])) { foreach ($postData['RssSources']['settings'] as $name => $value) { $sourcesSettings = new SourcesSettings(); $sourcesSettings->source_id = $model->source_id; $sourcesSettings->name = $name; $sourcesSettings->value = $value; $sourcesSettings->save(); } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }