dqsvf28682 2016-06-21 15:05
浏览 39

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

i want to search the column username and get the id of that username in the user table

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,
        ]);
     }
    }

view/user/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>

to achieve this where i have to place the code i am new to yii2 framework thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 我的数据无法存进链表里
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端