Yes of course you can. You have several options:
Solution 1 is the worst solution, but the answer to your question
change the model search function (or create a new function). Search functions usually look like this:
public function search($params) { $query = Bookmark::find()->where('status <> "deleted"'); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => Yii::$app->session->get(get_parent_class($this) . 'Pagination'), ], ]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere([ 'status' => $this->status, 'id' => $this->id, 'reminder' => $this->reminder, 'order' => $this->order, 'update_time' => $this->update_time, 'update_by' => $this->update_by, 'create_time' => $this->create_time, 'create_by' => Yii::$app->user->id, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
You can change it to something like
public function search($params) { $query = Bookmark::find()->where('status <> "deleted"'); if (!($this->load($params) && $this->validate())) { THROW AN ERROR SOMEHOW HERE } $query->andFilterWhere([ 'status' => $this->status, 'id' => $this->id, 'reminder' => $this->reminder, 'order' => $this->order, 'update_time' => $this->update_time, 'update_by' => $this->update_by, 'create_time' => $this->create_time, 'create_by' => Yii::$app->user->id, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'url', $this->url]); return $query->all(); }
however, this will return all the records to you, because ActiveDataProvider will take care of pagination based on the given request.
Solution 2, the best solution
read the first example here http://www.yiiframework.com/doc-2.0/yii-data-activedataprovider.html . You can call ->getModels() on ActiveDataProvider to get the actual records. No changes required for the search function. Do whatever you want with an array.
Solution 3 and all that I use all the time
Use ActiveDataProvider with ListView. The list view allows you to create a list of records, but you do not want it to be a table. I personally do this in many places, and it works very well. I sometimes convert arrays to ArrayDataProvider to use it. More information about data providers here: http://www.yiiframework.com/doc-2.0/guide-output-data-providers.html