/** * @param $params * @return ActiveDataProvider */ public function search($params) { //$query = Setting::find(); $query = Setting::find()->select('section, COUNT(*) as count')->distinct()->where('section is not null')->groupBy(['section']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } // $query->andFilterWhere( // [ // 'id' => $this->id, // 'active' => $this->active, // 'section' => $this->section, // ] // ); // // $query->andFilterWhere(['like', 'key', $this->key]) // ->andFilterWhere(['like', 'value', $this->value]); // // return $dataProvider; }
/** * Updates an existing Setting. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $section * @return mixed */ public function actionUpdate($section) { //$section = Yii::$app->request->get('section', null); $model = Setting::find()->where('section=:s', [':s' => $section])->all(); $data = Yii::$app->request->post('Setting'); if ($data) { foreach ($data['key'] as $i => $v) { $s = $this->findModel($i); $s->section = $data['section']; $s->key = $v; $s->value = $data['value'][$i]; $s->type = 'string'; $s->save(); } return $this->redirect(['index']); } else { // if ($model->load(Yii::$app->request->post()) && $model->save()) { // return $this->redirect(['view', 'id' => $model->id]); // } else { return $this->render('update', ['model' => $model]); } }