Example #1
0
 /**
  * Возвращает массив с конфигурацией
  * @return array
  */
 protected function getConfig()
 {
     if ($this->_config === null) {
         $models = Model::find()->published()->all();
         $this->_config = ArrayHelper::map($models, "key", "value");
     }
     return $this->_config;
 }
 /**
  * Отображение и сохранение конфигурации
  * @return string|\yii\web\Response
  */
 public function actionIndex()
 {
     $searchModel = new Config(["scenario" => ActiveRecord::SCENARIO_SEARCH]);
     $models = Config::find()->orderBy(["id" => SORT_DESC])->all();
     if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) {
         foreach ($models as $setting) {
             $setting->save(false);
         }
         return $this->refresh();
     }
     return $this->render('index', ['models' => $models, "searchModel" => $searchModel]);
 }