在Kartik Yii2导出中,导出为Excel时会出现非法字符串偏移' class'。这是我的代码:
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\Pjax;
use yii\bootstrap\Model;
use yii\helpers\Url;
use kartik\export\ExportMenu;
$this->title = Yii::t('app', 'Pelamar Doktor Berdasarkan Usia');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="temppelamardoktorusia-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<!-- <p>
<?= Html::a(Yii::t('app', 'Create Jumlah Pelamar Doktor'), ['create'], ['class' => 'btn btn-success']) ?>
</p> -->
<?php
$gridColumns = [
['class' => 'yii\grid\SerialColumn'],
'TahunDaftar',
'lessthan25',
'btween25to29',
'btween30to34',
'btween35to39',
'btween40to44',
'btween45to49',
'morethaneqs50',
'NotComplete',
'Total',
['class' => 'yii\grid\ActionColumn'],
];
//Renders a export dropdown menu
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'fontAwesome' => true,
]);
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'exportConfig'=> [
GridView::CSV=>[
'label' => 'CSV',
'icon' => '',
'iconOptions' => '',
'showHeader' => false,
'showPageSummary' => false,
'showFooter' => false,
'showCaption' => false,
'filename' => 'yii',
'alertMsg' => 'created',
'options' => ['title' => 'Semicolon - Separated Values'],
'mime' => 'application/csv',
'config' => [
'colDelimiter' => ";",
'rowDelimiter' => "\r\n",
],
],
],
]); ?>
</div>
结果:非法字符串偏移&#39; class&#39;。 以下是错误消息:
答案 0 :(得分:0)
您导入错误的GridView
。
更改此内容:use yii\grid\GridView;
由Kartik's:use kartik\grid\GridView;