Adding CbuttonColumn to Csv Header Column array (Used in CgridView) - Yii Framework

你。 提交于 2020-01-07 05:46:21

问题


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.

Here is my code,

<?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,
    )); ?>

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


回答1:


Add this to $column :

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


来源:https://stackoverflow.com/questions/20944676/adding-cbuttoncolumn-to-csv-header-column-array-used-in-cgridview-yii-framew

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!