将CbuttonColumn添加到Csv Header列数组(在CgridView中使用) - Yii Framework

时间:2014-01-06 06:58:39

标签: yii

我正在尝试将删除按钮添加到CgridView,我正在从CSV文件头显示CgridView列。我在数组中存储Csv列名称,现在我想再添加一个按钮列来删除记录。

这是我的代码,

<?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数组

1 个答案:

答案 0 :(得分:0)

将此添加到$ column:

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