首页 > 解决方案 > 如何将gridview行显示到特定视图?

问题描述

这是我的网格: 在此处输入图像描述

我进行了查询并创建了一个数据提供程序以在 gridview 中查看,现在我想在特定视图中查看每一行。单击预览时如何获取要发送的所有行数据?

在我的控制器上

    $model = new Aviso();

    if ($model->load(Yii::$app->request->post())) {

        $seg = $model->seguradora;

        $seguradora =  SeguradoraSearch::getNomeSeg($seg);

        $query = new Query; 

        $query->select(['apolice_idapolice','nome','email', 'contacto','premio','data_final','situacao'])
              ->from('seguro')
              ->innerJoin('cliente', 'cliente_idcliente = idcliente')
              ->where(['between','data_final' ,$model->data_inicio,$model->data_final])
              ->andWhere(['situacao'=> "Pendente"])
              ->andWhere(['seguradora_idseguradora'=>$seg]);

        $dataAviso = new ActiveDataProvider([
        'query' => $query,
    ]);
               return $this->render('index',[
                  'dataProvider' => $dataAviso,'segName'=>$seguradora,

        ]);
    }
    return $this->render('create', [
        'model' => $model,
    ]);
}

在我的索引上

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'summary' => '',    
    'columns' => [
         ['class' => 'yii\grid\SerialColumn'],

        ['attribute'=>'nome',
         'label'=>  'Cliente', 
        ],
        ['attribute'=>'email',
         'label'=>  'E-mail', 
        ], 

        ['attribute'=>'apolice_idapolice',
         'label'=>  'Apolice', 
        ], 

        'contacto',
        ['attribute'=>'premio',
        'format' => ['decimal', 2],
         'label'=>  'Valor (Mts)', 
        ],              
        'data_final',
        ['attribute'=>'situacao',
         'label'=>  'Situação', 
        ], 
        ['class' => 'yii\grid\ActionColumn', 'template' => '{view}','header' => 'visualizar' ],

    ],
]); ?>

<?php Pjax::end(); ?>

我想单击图标可视化工具并在特定视图上进行渲染。

标签: phpyii2yii2-advanced-appyii2-basic-app

解决方案


您可以使用模板和 urlCreator 以正确的方式配置 ActionColumn

假设 $model->id 是视图的目标 id

['class' => 'yii\grid\ActionColumn',
    'template' => '{view}',                        
     'urlCreator' => function ($action, $model, $key, $index) {
         if ($action === 'view') {
          return \yii\helpers\Url::to(['your-controller/your-action', 'id' => $model->id]); 
         }
     }
],

推荐阅读