/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = profile::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'first_name', 'last_name', 'birthdate', 'genderName' => ['asc' => ['gender.gender_name' => SORT_ASC], 'desc' => ['gender.gender_name' => SORT_DESC], 'label' => 'Gender'], 'profileIdLink' => ['asc' => ['profile.id' => SORT_ASC], 'desc' => ['Profile.id' => SORT_DESC], 'label' => 'ID'], 'userLink' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC], 'label' => 'User']]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['gender'])->joinWith(['user']); return $dataProvider; } $this->addSearchParameter($query, 'profile.id'); $this->addSearchParameter($query, 'first_name', true); $this->addSearchParameter($query, 'last_name', true); $this->addSearchParameter($query, 'birthdate'); $this->addSearchParameter($query, 'gender_id'); $this->addSearchParameter($query, 'created_at'); $this->addSearchParameter($query, 'updated_at'); $this->addSearchParameter($query, 'user_id'); // filter by gender name $query->joinWith(['gender' => function ($q) { $q->where('gender.gender_name LIKE "%' . $this->genderName . '%"'); }])->joinWith(['user' => function ($q) { $q->where('user.id LIKE "%' . $this->userId . '%"'); }]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = profile::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id, 'user_id' => $this->user_id, 'birthdate' => $this->birthdate, 'gender_id' => $this->gender_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name]); return $dataProvider; }
/** * Finds the profile model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return profile the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = profile::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }