public function beforeSave($insert) { if ($this->order == null) { $this->order = MainTheme::find()->select("MAX(`order`)")->scalar() + 1; } return parent::beforeSave($insert); // TODO: Change the autogenerated stub }
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 down() { \common\models\MainTheme::deleteAll(); }
public static function find() { return parent::find()->where(['enabled' => 1]); }
/** * @param MainTheme $theme */ public function loadTheme($theme) { $this->setAttributes(['name' => $theme->name, 'color' => $theme->color, 'order' => $theme->order, 'enabled' => $theme->enabled, 'categories' => $theme->getCategories(), 'articles' => $theme->getArticles(), 'id' => $theme->id, 'titleWords' => $theme->titleWords, 'textWords' => $theme->textWords]); }