Sfoglia il codice sorgente

Backend : Filtre utilisateur

Pouvoir filtrer les utilisateurs par nom, prenom, telephone, email dans la section "Utilisateurs".
master
keun 8 anni fa
parent
commit
d131c1f9fa
2 ha cambiato i file con 54 aggiunte e 8 eliminazioni
  1. +17
    -4
      backend/controllers/UserController.php
  2. +37
    -4
      backend/views/user/index.php

+ 17
- 4
backend/controllers/UserController.php Vedi File

@@ -63,14 +63,27 @@ class UserController extends BackendController
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' =>
(new \yii\db\Query())
$params = Yii::$app->request->queryParams;
$query = (new \yii\db\Query())
->select('*')
->from('user, user_etablissement')
->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.actif = 1')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement)
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id_etablissement) ;
if(isset($params['nom']))
$query->andFilterWhere(['like', 'nom', $params['nom']]);
if(isset($params['prenom']))
$query->andFilterWhere(['like', 'prenom', $params['prenom']]) ;
if(isset($params['email']))
$query->andFilterWhere(['like', 'email', $params['email']]) ;
if(isset($params['telephone']))
$query->andFilterWhere(['like', 'telephone', $params['telephone']]) ;
$dataProvider = new ActiveDataProvider([
'query' => $query
]);
$etablissement = Etablissement::find()

+ 37
- 4
backend/views/user/index.php Vedi File

@@ -20,11 +20,44 @@ $this->params['breadcrumbs'][] = $this->title;
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => true,
'columns' => [
'nom',
'prenom',
'telephone',
'email',
[
'attribute' => 'nom',
'filter' => Html::input(
'string',
'nom',
isset(Yii::$app->request->queryParams['nom']) ? Html::encode(Yii::$app->request->queryParams['nom']) : '',
[ 'class' => 'form-control']
)
],
[
'attribute' => 'prenom',
'filter' => Html::input(
'string',
'prenom',
isset(Yii::$app->request->queryParams['prenom']) ? Html::encode(Yii::$app->request->queryParams['prenom']) : '',
['class' => 'form-control']
)
],
[
'attribute' => 'telephone',
'filter' => Html::input(
'string',
'telephone',
isset(Yii::$app->request->queryParams['telephone']) ? Html::encode(Yii::$app->request->queryParams['telephone']) : '',
['class' => 'form-control']
)
],
[
'attribute' => 'email',
'filter' => Html::input(
'string',
'email',
isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '',
['class' => 'form-control']
)
],
[
'attribute' => 'credit',
'format' => 'raw',

Loading…
Annulla
Salva