问题
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