/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = bookread::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'id' => $this->id]); $query->andFilterWhere(['like', 'book', $this->book])->andFilterWhere(['like', 'authors', $this->authors])->andFilterWhere(['like', 'year_published', $this->year_published])->andFilterWhere(['like', 'year_read', $this->year_read])->andFilterWhere(['like', 'place_read', $this->place_read])->andFilterWhere(['like', 'time_of_life', $this->time_of_life])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by]); return $dataProvider; }
public function actionXml() { $models = bookread::find()->all(); $data = array_map(function ($model) { return $model->attributes; }, $models); $response = Yii::$app->response; $response->format = Response::FORMAT_XML; $response->data = $data; return $response; }
/** * Lists all book models. * @return mixed */ public function actionIndex() { $searchModel = new bookread(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }