/** * Creates data provider instance with search query applied * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = MediaModel::find(); $query->innerJoinWith(['mediaAuthor' => function ($query) { /* @var $query \yii\db\ActiveQuery */ return $query->from(['user' => User::tableName()]); }])->from(['media' => $this->tableName()]); $query->leftJoin(['post' => Post::tableName()], 'media.post_id = post.id'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['id' => SORT_DESC]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['media.id' => $this->id, 'media.author' => $this->author, 'post_id' => $this->post_id, 'media.comment_count' => $this->comment_count]); $query->andFilterWhere(['like', 'media.title', $this->title])->andFilterWhere(['like', 'media.excerpt', $this->excerpt])->andFilterWhere(['like', 'media.content', $this->content])->andFilterWhere(['like', 'media.password', $this->password])->andFilterWhere(['like', 'media.slug', $this->slug])->andFilterWhere(['like', 'mime_type', $this->mime_type])->andFilterWhere(['like', 'media.comment_status', $this->comment_status])->andFilterWhere(['like', 'media.date', $this->date])->andFilterWhere(['like', 'media.modified', $this->modified])->andFilterWhere(['like', 'post.title', $this->post_title])->andFilterWhere(['like', 'user.username', $this->username]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MediaModel::find()->from(['media' => $this->tableName()]); $query->innerJoinWith(['mediaAuthor' => function ($query) { /* @var $query \yii\db\ActiveQuery */ return $query->from(['author' => User::tableName()]); }]); $query->leftJoin(['post' => Post::tableName()], 'media.media_post_id = post.id'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ArrayHelper::merge($dataProvider->sort->attributes, ['username' => ['asc' => ['username' => SORT_ASC], 'desc' => ['username' => SORT_DESC], 'label' => 'Author', 'value' => 'username']]), 'defaultOrder' => ['id' => SORT_DESC]]); $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, 'media_author' => $this->media_author, 'media_post_id' => $this->media_post_id, 'media_comment_count' => $this->media_comment_count]); $query->andFilterWhere(['like', 'media_title', $this->media_title])->andFilterWhere(['like', 'media_excerpt', $this->media_excerpt])->andFilterWhere(['like', 'media_content', $this->media_content])->andFilterWhere(['like', 'media_password', $this->media_password])->andFilterWhere(['like', 'media_slug', $this->media_slug])->andFilterWhere(['like', 'media_mime_type', $this->media_mime_type])->andFilterWhere(['like', 'media_comment_status', $this->media_comment_status])->andFilterWhere(['like', 'media_date', $this->media_date])->andFilterWhere(['like', 'media_modified', $this->media_modified])->andFilterWhere(['like', 'post.post_title', $this->post_title])->andFilterWhere(['like', 'author.username', $this->username]); return $dataProvider; }
/** * Lists all User models. * @return mixed */ public function actionIndex() { $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }