/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Cbs::find(); $query->joinWith(['createdBy']); $query->orderBy(['status' => SORT_ASC, 'name' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['createdBy.username'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'url', $this->description])->andFilterWhere(['like', 'version', $this->version])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getCbs() { return $this->hasMany(Cbs::className(), ['created_by' => 'id']); }