Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Settings::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value]);
     return $dataProvider;
 }
Beispiel #2
0
 public function actionSettings()
 {
     $languages = Languages::find()->select(['url', 'name'])->all();
     $model = new SettingsForm();
     $model->frontend_default_language = Languages::getDefaultLanguage()->url;
     $model->setAttributes(ArrayHelper::map(Settings::find()->all(), 'name', 'value'));
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         foreach ($model->attributes as $key => $value) {
             Settings::updateAll(['value' => (string) $value], '`name` = :key', [':key' => $key]);
         }
         Languages::setDefaultLanguage($model->frontend_default_language);
         Yii::$app->getSession()->setFlash('success', Yii::t('main', 'Settings successfully saved'));
     }
     return $this->render('settings', ['model' => $model, 'languages' => $languages]);
 }
 public function actionIndex()
 {
     $model = new Settings();
     $dataProvider = new ActiveDataProvider(['query' => Settings::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]);
 }