public function search($params) { $query = Preferences::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['changemark' => $this->changemark, 'id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'codes', $this->codes])->andFilterWhere(['like', 'name1', $this->name1])->andFilterWhere(['like', 'classmark', $this->classmark])->andFilterWhere(['like', 'classmarkcn', $this->classmarkcn]); return $dataProvider; }
public function actionJson($classmark = '') { if ($classmark) { $models = Preferences::find()->andFilterWhere(['classmark' => $classmark])->all(); $data = array_map(function ($model) { return $model->attributes; }, $models); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->data = $data; $response->send(); //等同于 return $response; } return ''; }