本文介绍了将 CbuttonColumn 添加到 Csv Header Column 数组(在 CgridView 中使用) - Yii Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 CgridView 添加删除按钮,我正在显示来自 CSV 文件标题的 CgridView 列.我将 Csv 列名称存储在数组中,现在我想再添加一个按钮列以删除记录.

I am trying to add Delete button to CgridView , I am displaying CgridView columns from CSV file headers . I am storing Csv columns names in array, Now i want to add one more button column to delete the record.

这是我的代码,

<?php 
$file = fopen('D:/xampp/htdocs/ccvv7/images/importcsv/load.csv', 'r');
$data = array();
while (($line = fgetcsv($file)) !== FALSE) {

    $data[] = $line;
}
fclose($file);
$columns = array();

foreach ($data[0] as $key => $value) {
    $columns[] = array(
        'name' => $key,
        'header' => $value,
    );
}
$data = array_slice($data, 1);
$dataProvider = new CArrayDataProvider($data, array(
    'keyField' => 0,
));?>

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' =>'BCImported-grid',
'dataProvider' => $dataProvider,
'columns' => $columns,
    )); ?>

请查看代码,现在我需要在 $columns 数组中再添加一个按钮列

Please look into the code, now i need to add one more button column to $columns array

推荐答案

将此添加到 $column :

Add this to $column :

        array(
            'class'=>'CButtonColumn',
            'template'=>'{delete}',
            'deleteButtonUrl'=>'Yii::app()->controller->createUrl("delete",array("id"=>$data["id"]))',
        ),

这篇关于将 CbuttonColumn 添加到 Csv Header Column 数组(在 CgridView 中使用) - Yii Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 21:16