コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: PerfilSearch.php プロジェクト: rvences/tu3_yii2
 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;
 }
コード例 #3
0
ファイル: PerfilController.php プロジェクト: rvences/tu3_yii2
 /**
  * Deletes an existing Perfil model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = Perfil::find()->where(['user_id' => Yii::$app->user->identity->id])->one();
     $this->findModel($model->id)->delete();
     // Si se deja solo redirect(['index']) el controlador redireccionará a perfil/index
     return $this->redirect(['site/index']);
     /*
             $this->findModel($id)->delete();
     
             return $this->redirect(['index']);*/
 }
コード例 #4
0
 /**
  * Deletes an existing Perfil model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * 
  * @param string $id        	
  * @return mixed
  */
 public function actionDelete()
 {
     $model = Perfil::find()->where(['user_id' => Yii::$app->user->identity->id])->one();
     $this->findModel($model->id)->delete();
     return $this->redirect(['site/index']);
 }