瀏覽代碼

Backend : Filtre utilisateur

Pouvoir filtrer les utilisateurs par nom, prenom, telephone, email dans la section "Utilisateurs".
prodstable
keun 8 年之前
父節點
當前提交
d131c1f9fa
共有 2 個文件被更改,包括 54 次插入8 次删除
  1. +17
    -4
      backend/controllers/UserController.php
  2. +37
    -4
      backend/views/user/index.php

+ 17
- 4
backend/controllers/UserController.php 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存