2

我想在 Yii2 中导出我的表格。这是我的桌子: 在此处输入图像描述

在 Kartik Yii2 导出中,在导出为 Excel 时出现非法字符串偏移“类”。这是我的代码:

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

结果:非法字符串偏移 'class'。这是错误消息:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述 我究竟做错了什么?有没有办法解决这个问题?提前致谢

4

1 回答 1

0

您正在导入错误的GridView.

改变这个:use yii\grid\GridView;

通过 Kartik 的:use kartik\grid\GridView;

于 2017-07-26T15:35:28.507 回答