public function save() { $model = Configuration::findOne($this->id); foreach ($this as $key => $value) { $model->{$key} = $value; } return $model->save(); }
private static function getConfig() { if (\Yii::$app->cache->exists('configuration') && !\Yii::$app->request->get('disableConfigCache')) { return \Yii::$app->cache->get('configuration'); } if (!self::$configuration) { self::$configuration = ArrayHelper::map(Configuration::find()->select(['key', 'value'])->asArray()->all(), 'key', 'value'); \Yii::$app->cache->set('configuration', self::$configuration, 600); } return self::$configuration; }
public function edit($paramsForThisPage) { $params = Configuration::find()->where(['in', 'key', $paramsForThisPage])->all(); $model = new ConfigurationModel(); $model->loadFields($params); if (\Yii::$app->request->post('ConfigurationFieldModel')) { $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]); }
/** * @param $key * * @return bool */ public function set($key) { /** @var Configuration $config */ $config = Configuration::find()->select(['id', 'value', 'type'])->with(['translations'])->where(['id' => $key, 'published' => 1])->asArray()->one(); if (null === $config) { return false; } $this->configs[$key]['type'] = (int) $config['type']; $this->configs[$key][$this->defaultLanguage] = $config['value']; foreach ($config['translations'] as $item) { $this->configs[$key][$item['language']] = $item['value']; } return true; }
/** * @return \yii\db\ActiveQuery */ public function getModel() { return $this->hasOne(Configuration::className(), ['id' => 'model_id']); }
public function beforeValidate() { if (parent::beforeValidate()) { $this->setScenario($this->getTypeScenario()); return true; } return false; }