/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Perfil::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, 'fecha_nacimiento' => $this->fecha_nacimiento, 'genero_id' => $this->genero_id, 'created_at' => $this->created_at, 'update_at' => $this->update_at]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'apellidos', $this->apellidos]); return $dataProvider; }
public function search($params) { $query = Perfil::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['attributes' => ['id', 'nombre', 'apellido', 'fecha_nacimiento', 'perfilIdLink' => ['asc' => ['perfil.id' => SORT_ASC], 'desc' => ['perfil.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(['user']); return $dataProvider; } $this->addSearchParameter($query, 'id'); $this->addSearchParameter($query, 'nombre', true); $this->addSearchParameter($query, 'apellido', true); $this->addSearchParameter($query, 'fecha_nacimiento'); $this->addSearchParameter($query, 'created_at'); $this->addSearchParameter($query, 'updated_at'); $this->addSearchParameter($query, 'user_id'); // filtrar por usuario $query->joinWith(['user' => function ($q) { $q->andFilterWhere(['=', 'user.id', $this->user]); }]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getPerfiles() { return $this->hasMany(Perfil::className(), ['genero_id' => 'id']); }
/** * Obtiene de la tabla Perfil el campo USER_ID que hace referencia a User(id) * @return \yii\db\ActiveQuery */ public function getPerfil() { return $this->hasOne(Perfil::className(), ['user_id' => 'id']); }
/** * Finds the Perfil model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Perfil the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Perfil::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }