如何在pjax表单中仅在表的列上执行自定义搜索,并将搜索栏放在yii 2中所有页面共有的布局中

时间:2016-06-21 15:05:46

标签: php mysql yii

我想搜索列用户名并在用户表中获取该用户名的ID

usercontroller.php

  public function actionIndex()
  {
    $searchModel = new UserSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    if (Yii::$app->request->isPjax) {
        return $this->renderPartial('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
       } else {
        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
     }
    }

查看/用户/ index.php的     

<h1><?= Html::encode($this->title) ?></h1>
 <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

 <p>
 <?= Html::a(Yii::t('app', 'Create User'), ['create'], 
 ['class' => 'btn                  btn-success']) ?>
   </p>
  <?php Pjax::begin(); ?>
   <?= GridView::widget([
      'dataProvider' => $dataProvider,
      'filterModel' => $searchModel,
      'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        'id',
        'username',
        'email:email',
        'password',
        'user_type',
        // 'newsletters',
        // 'terms',
        // 'auth_key',

        ['class' => 'yii\grid\ActionColumn'],
    ],
    ]); ?>
    <?php Pjax::end(); ?>
    </div>

实现这一目标,我必须将代码放在yii2框架中 提前谢谢

0 个答案:

没有答案