php - 如何将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(); ?>
我想单击图标可视化工具并在特定视图上进行渲染。
解决方案
您可以使用模板和 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]);
}
}
],
推荐阅读
- loops - 我的 VHDL 标志需要终止
- javascript - 在我的鼓应用程序中调度操作后,我的元素不会更新显示
- amazon-s3 - 如何将 apple-app-site-association 文件添加到我的 Ember 应用程序?
- python-3.x - 使用 pip 安装 jupyter 失败
- python - 如何从 pymongo 聚合中的日期时间对象中删除毫秒
- javascript - jQuery 问题:无法读取未定义的属性
- angular - 您是否必须取消订阅组件中的 QueryList?
- visual-studio-code - 如何配置 VS Code 以使用 cubeMX 构建和调试 STM32 项目 - Windows 10
- ios - iOS 键盘语言在特定语言中不会改变
- jekyll - 添加可选权重以覆盖 Jekyll 中项目的默认排序