コード例 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Entrepreneur::find();
     $query->joinWith(['user', 'profile']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['username'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]];
     $dataProvider->sort->attributes['email'] = ['asc' => ['user.email' => SORT_ASC], 'desc' => ['user.email' => SORT_DESC]];
     $dataProvider->sort->attributes['name'] = ['asc' => ['profile.name' => SORT_ASC], 'desc' => ['profile.name' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'profile.name', $this->name])->andFilterWhere(['like', 'profile.user_id', $this->user_id])->andFilterWhere(['like', 'user.email', $this->email]);
     $query->andFilterWhere(['like', 'plkn', $this->plkn]);
     return $dataProvider;
 }