frontend\modules\tweet\models\TweetSearch::search PHP Method

    public function search($params)
    {
        $query = Tweet::find()->with('user');
        $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['order' => SORT_ASC, 'updated_at' => SORT_DESC]]]);
        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }
        $query->andFilterWhere(['id' => $this->id, 'post_meta_id' => $this->post_meta_id, 'user_id' => $this->user_id, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'favorite_count' => $this->favorite_count, 'like_count' => $this->like_count, 'thanks_count' => $this->thanks_count, 'hate_count' => $this->hate_count, 'status' => $this->status, 'order' => $this->order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
        $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags]);
        return $dataProvider;
    }

Usage Example

Beispiel #1
0
 public function actionIndex()
 {
     $searchModel = new TweetSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => Tweet::TYPE, 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     $model = new Tweet();
     return $this->render('index', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }