/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Item::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(['id' => $this->id, 'user_id' => $this->user_id, 'parent_id' => $this->parent_id, 'branch_id' => $this->branch_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'active' => $this->active]); $query->andFilterWhere(['like', 'parent_class', $this->parent_class])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionList(ActiveRecord $parent) { $items = Item::find()->where(['parent_class' => get_class($parent), 'parent_id' => $parent->primaryKey, 'active' => true])->orderBy(['created_at' => SORT_DESC])->all(); return $this->renderPartial('list', ['dataProvider' => new \yii\data\ArrayDataProvider(['allModels' => $items])]); }