public function actionEdit($id) { $theme = MainTheme::findOne($id); if (!$theme) { throw new NotFoundHttpException("Тема с идентификатором {$id} не найдена!"); } $model = new MainThemeForm(); $model->loadTheme($theme); if (\Yii::$app->request->post('MainThemeForm') && $model->load(\Yii::$app->request->post())) { if ($model->save()) { \Yii::$app->session->setFlash('success', 'Тема сохранена!'); } else { \Yii::$app->session->setFlash('error', 'Произошла ошибка при сохранении темы!'); } } return $this->render('edit', ['model' => $model]); }
public function save() { if (!$this->validate()) { return false; } if (!empty($this->id)) { $theme = MainTheme::findOne($this->id); } if (!isset($theme) || empty($theme)) { $theme = new MainTheme(); } $theme->setAttributes(['name' => $this->name, 'color' => $this->color, 'order' => $this->order, 'enabled' => $this->enabled, 'titleWords' => $this->titleWords, 'textWords' => $this->textWords]); $theme->setCategories($this->categories); $theme->setArticles($this->articles); if ($theme->save(false)) { $this->id = $theme->id; } return !empty($this->id); }