Example #1
0
 /**
  * @return array|string|Response
  */
 public function run()
 {
     $models = ConfigModel::find()->orderBy(['sort' => SORT_ASC])->indexBy('name')->all();
     if (Model::loadMultiple($models, Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validateMultiple($models, 'value');
         }
         $result = true;
         /** @var ConfigModel $model */
         foreach ($models as $model) {
             $result = $result && $model->save(true, ['value']);
             Config::clearCache($model->name);
         }
         if ($result) {
             Yii::$app->session->setFlash('success', $this->successMessage);
             return $this->controller->redirect([$this->id]);
         }
     }
     return $this->controller->render($this->viewPath, ['models' => $models]);
 }
Example #2
0
 /**
  * Delete setting by name
  * @param string $name
  * @return bool
  */
 public static function delete($name)
 {
     \Yii::$app->cache->delete(static::$cachePrefix . $name);
     return ConfigModel::deleteAll(['name' => $name]) > 0;
 }