Php 如何将gridview行显示到特定视图?
这是我的网格: 我做了一个查询并创建了一个dataprovider以在gridview中查看,现在我想在特定视图中查看每一行。单击“预览”时,如何获取要发送的所有行数据 在我的控制器上Php 如何将gridview行显示到特定视图?,php,yii2,yii2-advanced-app,yii2-basic-app,Php,Yii2,Yii2 Advanced App,Yii2 Basic App,这是我的网格: 我做了一个查询并创建了一个dataprovider以在gridview中查看,现在我想在特定视图中查看每一行。单击“预览”时,如何获取要发送的所有行数据 在我的控制器上 $model = new Aviso(); if ($model->load(Yii::$app->request->post())) { $seg = $model->seguradora; $seguradora = Segur
$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(); ?>
我想单击visualizar图标并在特定视图上进行渲染。您可以使用template和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]);
}
}
],
你好,李珍,谢谢你的贡献,但这对我的案子不起作用。我没有为这个类定义模型,如果我有它的话,那就很容易了。这个网格来自一个查询生成器,我创建了一个数据提供者。这就是为什么视图按钮找不到模型的原因。在这种情况下,我需要一个在特定视图上查看行的解决方案。@CandidoNgovo。。。对于gridview操作列,您只需更改代码并调整我的答案中的示例。。。我不是李珍。。。