Yii Framework Forum: Problems Setting Up Kartik Yii2 Export Extension - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problems Setting Up Kartik Yii2 Export Extension Rate Topic: -----

#1 User is offline   R Hamzeh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 05-June 14

Posted 21 February 2015 - 06:22 AM

Hi, I'm new to Yii and I'm developing a database application that reads tables from MySQL. I needed the user to be able to export data as CSV or PDF, so I downloaded Kartik Yii2 Export Extension. I don't know how am I supposed to configure my settings to run this extension, I read the guide but I didn't understand how to fix this error:

Invalid Configuration – yii\base\InvalidConfigException
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.

Here is my code:

Models/industrial.php:
<?php

namespace app\models;

use yii\db\ActiveRecord;

class Industrial extends ActiveRecord
{
}





controller/IndustrialController.php:



<?php

namespace app\controllers;


use yii\web\Controller;
use yii\data\Pagination;
use app\models\industrial;
use yii\data\ActiveDataProvider;

class IndustrialController extends Controller
{

	
    public function actionIndex()
    {
		$dataProvider=new ActiveDataProvider('Industrial', array(

    'pagination'=>array(
        'pageSize'=>20,
    ),
));
        $query = industrial::find();

        $pagination = new Pagination([
            'defaultPageSize' => 20,
            'totalCount' => $query->count(),
        ]);

        $industrials = $query->orderBy('Company_Name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();
			
			
		

        return $this->render('index', [
            'industrials' => $industrials,
            'pagination' => $pagination,
			'dataProvider'=>$dataProvider,
        ]);
		


}
}







views/industrial/index.php:



<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
?>
<h1>Industrial Companies</h1>
<ul>
<?php

use kartik\export\ExportMenu;

use kartik\grid\GridView;

$gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
    'id',
    'name',
    [
        'attribute'=>'Name',
        'label'=>'Name',
        'vAlign'=>'middle',
        'width'=>'190px',
        'value'=>function ($model, $key, $index, $widget) { 
            return Html::a($model->Name, '#', []);
        },
        'format'=>'raw'
    ],
    'Name',
    'Location',
    'Telephone',
    
];
echo ExportMenu::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'fontAwesome' => true,
    'dropdownOptions' => [
        'label' => 'Export All',
        'class' => 'btn btn-default'
    ]
]) . "<hr>\n".
GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'export' => [
        'fontAwesome' => true,
    ]
]);



$array = (array) $industrials;



function build_table($array){

    // start table

    $html = '<table class="altrowstable" id="alternatecolor">';

    // header row

    $html .= '<tr>';

    foreach($array[0] as $key=>$value){

            $html .= '<th>' . $key . '</th>';

        }

    $html .= '</tr>';

    // data rows

    foreach( $array as $key=>$value){

        $html .= '<tr>';

        foreach($value as $key2=>$value2){

            $html .= '<td>' . $value2 . '</td>';

        }

        $html .= '</tr>';

    }

    // finish table and return it

    $html .= '</table>';

    return $html;

}



echo build_table($array);

?>


<?= LinkPager::widget(['pagination' => $pagination]) ?>





Please help me.
0

#2 User is offline   R Hamzeh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 05-June 14

Posted 26 February 2015 - 05:59 AM

Exception
Invalid Configuration – yii\base\InvalidConfigException
The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.
    1. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\data\ActiveDataProvider.php at line 95
    2. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\data\BaseDataProvider.php – yii\data\ActiveDataProvider::prepareModels() at line 79
    3. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\data\BaseDataProvider.php – yii\data\BaseDataProvider::prepare() at line 92
    4. in C:\xampp\htdocs\basic\vendor\kartik-v\yii2-export\ExportMenu.php – yii\data\BaseDataProvider::getModels() at line 667
    661662663664665666667668669670671672673

            $provider = $this->dataProvider;
            /** @var Model $model */
            if ($provider instanceof yii\data\ActiveDataProvider && $provider->query instanceof yii\db\ActiveQueryInterface) {
                $model = new $provider->query->modelClass;
                return $model->getAttributeLabel($attribute);
            } else {
                $models = $provider->getModels();
                if (($model = reset($models)) instanceof Model) {
                    return $model->getAttributeLabel($attribute);
                } else {
                    return Inflector::camel2words($attribute);
                }
            }

    5. in C:\xampp\htdocs\basic\vendor\kartik-v\yii2-export\ExportMenu.php – kartik\export\ExportMenu::getAttributeLabel('id') at line 644
    638639640641642643644645646647648649650

            $label = Yii::t('kvexport', 'Column') . ' ' . ($key + 1);
            if (!empty($column->label)) {
                $label = $column->label;
            } elseif (!empty($column->header)) {
                $label = $column->header;
            } elseif (!empty($column->attribute)) {
                $label = $this->getAttributeLabel($column->attribute);
            } elseif (!$column instanceof \yii\grid\DataColumn) {
                $class = explode("\\", $column::classname());
                $label = Inflector::camel2words(end($class));
            }
            return trim(strip_tags(str_replace(['<br>', '<br/>'], ' ', $label)));
        }

    6. in C:\xampp\htdocs\basic\vendor\kartik-v\yii2-export\ExportMenu.php – kartik\export\ExportMenu::getColumnLabel(1, kartik\grid\DataColumn) at line 619
    613614615616617618619620621622623624625

                'type' => 'button',
                'data-toggle' => 'dropdown',
                'aria-haspopup' => 'true',
                'aria-expanded' => 'false',
            ], $this->columnSelectorOptions);
            foreach ($this->columns as $key => $column) {
                $selector[$key] = $this->getColumnLabel($key, $column);
            }
            $this->columnSelector = array_replace($selector, $this->columnSelector);
            if (!isset($this->selectedColumns)) {
                $keys = array_keys($this->columnSelector);
                $this->selectedColumns = array_combine($keys, $keys);
            }

    7. in C:\xampp\htdocs\basic\vendor\kartik-v\yii2-export\ExportMenu.php – kartik\export\ExportMenu::initColumnSelector() at line 538
    532533534535536537538539540541542543544

        /**
         * @inheritdoc
         */
        public function run()
        {
            $this->initI18N();
            $this->initColumnSelector();
            $this->setVisibleColumns();
            $this->initExport();
            if (!$this->_triggerDownload) {
                $this->registerAssets();
                echo $this->renderExportMenu();
                return;

    8. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\Widget.php – kartik\export\ExportMenu::run() at line 96
    9. in C:\xampp\htdocs\basic\views\industrial\index.php – yii\base\Widget::widget(['dataProvider' => yii\data\ActiveDataProvider, 'columns' => [['class' => 'yii\grid\SerialColumn'], 'id', 'name', ['attribute' => 'Name', 'label' => 'Name', 'vAlign' => 'middle', 'width' => '190px', ...], ...], 'fontAwesome' => true, 'dropdownOptions' => ['label' => 'Export All', 'class' => 'btn btn-default']]) at line 98
    9293949596979899100101102103104

        'columns' => $gridColumns,
        'fontAwesome' => true,
        'dropdownOptions' => [
            'label' => 'Export All',
            'class' => 'btn btn-default'
        ]
    ]) . "<hr>\n".
    GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => $gridColumns,
        'export' => [
            'fontAwesome' => true,
        ]

    10. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php – require('C:\xampp\htdocs\basic\views\indu...') at line 325
    11. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php – yii\base\View::renderPhpFile('C:\xampp\htdocs\basic\views\indu...', ['industrials' => [app\models\Industrial, app\models\Industrial, app\models\Industrial, app\models\Industrial, ...], 'pagination' => yii\data\Pagination, 'dataProvider' => yii\data\ActiveDataProvider]) at line 247
    12. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\View.php – yii\base\View::renderFile('C:\xampp\htdocs\basic\views\indu...', ['industrials' => [app\models\Industrial, app\models\Industrial, app\models\Industrial, app\models\Industrial, ...], 'pagination' => yii\data\Pagination, 'dataProvider' => yii\data\ActiveDataProvider], app\controllers\IndustrialController) at line 149
    13. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\Controller.php – yii\base\View::render('index', ['industrials' => [app\models\Industrial, app\models\Industrial, app\models\Industrial, app\models\Industrial, ...], 'pagination' => yii\data\Pagination, 'dataProvider' => yii\data\ActiveDataProvider], app\controllers\IndustrialController) at line 367
    14. in C:\xampp\htdocs\basic\controllers\IndustrialController.php – yii\base\Controller::render('index', ['industrials' => [app\models\Industrial, app\models\Industrial, app\models\Industrial, app\models\Industrial, ...], 'pagination' => yii\data\Pagination, 'dataProvider' => yii\data\ActiveDataProvider]) at line 42
    363738394041424344454647

     
     
            return $this->render('index', [
                'industrials' => $industrials,
                'pagination' => $pagination,
                'dataProvider'=>$dataProvider,
            ]);
     
     
     
    }
    }

    15. app\controllers\IndustrialController::actionIndex()
    16. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\InlineAction.php – call_user_func_array([app\controllers\IndustrialController, 'actionIndex'], []) at line 55
    17. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\Controller.php – yii\base\InlineAction::runWithParams(['r' => 'industrial/index', 'page' => '1']) at line 151
    18. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\Module.php – yii\base\Controller::runAction('index', ['r' => 'industrial/index', 'page' => '1']) at line 455
    19. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\web\Application.php – yii\base\Module::runAction('industrial/index', ['r' => 'industrial/index', 'page' => '1']) at line 83
    20. in C:\xampp\htdocs\basic\vendor\yiisoft\yii2\base\Application.php – yii\web\Application::handleRequest(yii\web\Request) at line 375
    21. in C:\xampp\htdocs\basic\web\index.php – yii\base\Application::run() at line 12
    6789101112

     
    require(__DIR__ . '/../vendor/autoload.php');
    require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
     
    $config = require(__DIR__ . '/../config/web.php');
     
    (new yii\web\Application($config))->run();

$_GET = [
    'r' => 'industrial/index',
    'page' => '1',
];

$_SERVER = [
    'MIBDIRS' => 'C:/xampp/php/extras/mibs',
    'MYSQL_HOME' => '\\xampp\\mysql\\bin',
    'OPENSSL_CONF' => 'C:/xampp/apache/bin/openssl.cnf',
    'PHP_PEAR_SYSCONF_DIR' => '\\xampp\\php',
    'PHPRC' => '\\xampp\\php',
    'TMP' => '\\xampp\\tmp',
    'HTTP_HOST' => 'localhost',
    'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0',
    'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
    'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
    'HTTP_REFERER' => 'http://localhost/basic/web/index.php?r=site%2Findex',
    'HTTP_COOKIE' => '_identity=1bee636c09f5758cd56f3b60605530654277700567980b6f37c8bdde47330085s%3A28%3A%22%5B%22100%22%2C%22test100key%22%2C2592000%5D%22%3B; PHPSESSID=vbllg5jhvu0cl3ru9tjs5cj0g1; _csrf=05ae188cc11591d381d8aaf13b84af4389c721da97b03505ac0bfa65e2b90338s%3A32%3A%22YoxfQ0Pmu30dTtOGM1sVT_Jv8tus6Dp0%22%3B',
    'HTTP_CONNECTION' => 'keep-alive',
    'PATH' => 'C:\\Ruby\\bin;C:\\Rub\\bin;C:\\Program Files (x86)\\ImageMagick-6.5.6-Q8;C:\\Program Files (x86)\\ImageMagick-6.6.5-Q16;C:\\RailsInstaller\\Git\\cmd;C:\\RailsInstaller\\Ruby2.0.0\\bin;C:\\ImageMagick;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\C:\\HashiCorp\\Vagrant\\bin;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.4.4\\;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.4.4\\Doctrine extensions for PHP\\;C:\\Program Files (x86)\\Git\\cmd;C:\\Program Files\\MATLAB\\R2014a\\runtime\\win64;C:\\Program Files\\MATLAB\\R2014a\\bin;C:\\Program Files\\MATLAB\\R2014a\\polyspace\\bin;c:\\Program Files\\Microsoft SQL Server\\100\\Tools\\Binn\\;c:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\xampp\\php;C:\\ProgramData\\ComposerSetup\\bin;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\;C:\\Ruby\\bin;C:\\Rub\\bin;C:\\Program Files (x86)\\ImageMagick-6.5.6-Q8;C:\\Program Files (x86)\\ImageMagick-6.6.5-Q16;C:\\RailsInstaller\\Git\\cmd;C:\\RailsInstaller\\Ruby2.0.0\\bin;C:\\ImageMagick;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\C:\\HashiCorp\\Vagrant\\bin;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.4.4\\;C:\\Program Files (x86)\\MySQL\\MySQL Utilities 1.4.4\\Doctrine extensions for PHP\\;C:\\Program Files (x86)\\Git\\cmd;C:\\Program Files\\MATLAB\\R2014a\\runtime\\win64;C:\\Program Files\\MATLAB\\R2014a\\bin;C:\\Program Files\\MATLAB\\R2014a\\polyspace\\bin;C:\\OpenSSL-Win64;C:\\Python27;C:\\Python27\\Scripts;C:\\Python27;C:\\Python27\\Lib;C:\\Python27\\DLLs;C:\\Python27\\Lib\\lib-tk; C:\\Python27\\Scripts;C:\\Python27;C:\\Python27\\Scripts',
    'SystemRoot' => 'C:\\Windows',
    'COMSPEC' => 'C:\\Windows\\system32\\cmd.exe',
    'PATHEXT' => '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW',
    'WINDIR' => 'C:\\Windows',
    'SERVER_SIGNATURE' => '
Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15 Server at localhost Port 80

',
    'SERVER_SOFTWARE' => 'Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15',
    'SERVER_NAME' => 'localhost',
    'SERVER_ADDR' => '::1',
    'SERVER_PORT' => '80',
    'REMOTE_ADDR' => '::1',
    'DOCUMENT_ROOT' => 'C:/xampp/htdocs',
    'REQUEST_SCHEME' => 'http',
    'CONTEXT_PREFIX' => '',
    'CONTEXT_DOCUMENT_ROOT' => 'C:/xampp/htdocs',
    'SERVER_ADMIN' => 'postmaster@localhost',
    'SCRIPT_FILENAME' => 'C:/xampp/htdocs/basic/web/index.php',
    'REMOTE_PORT' => '61520',
    'GATEWAY_INTERFACE' => 'CGI/1.1',
    'SERVER_PROTOCOL' => 'HTTP/1.1',
    'REQUEST_METHOD' => 'GET',
    'QUERY_STRING' => 'r=industrial%2Findex&page=1',
    'REQUEST_URI' => '/basic/web/index.php?r=industrial%2Findex&page=1',
    'SCRIPT_NAME' => '/basic/web/index.php',
    'PHP_SELF' => '/basic/web/index.php',
    'REQUEST_TIME_FLOAT' => 1424868609.96700000762939453125,
    'REQUEST_TIME' => 1424868609,
];

$_COOKIE = [
    '_identity' => '1bee636c09f5758cd56f3b60605530654277700567980b6f37c8bdde47330085s:28:"["100","test100key",2592000]";',
    'PHPSESSID' => 'vbllg5jhvu0cl3ru9tjs5cj0g1',
    '_csrf' => '05ae188cc11591d381d8aaf13b84af4389c721da97b03505ac0bfa65e2b90338s:32:"YoxfQ0Pmu30dTtOGM1sVT_Jv8tus6Dp0";',
];

Yii Framework

2015-02-25, 13:50:17

Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.15

Yii Framework/2.0.2
‹

0

#3 User is offline   bazantj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 16-December 14

Posted 26 February 2015 - 06:05 AM

I am not sure I understand what you are trying to achive.

Still I would suggest to update your controller like this:

<?php

namespace app\controllers;


use yii\web\Controller;
use app\models\industrial;
use yii\data\ActiveDataProvider;

class IndustrialController extends Controller
{
    public function actionIndex()
    {
        $dataProvider=new ActiveDataProvider([
	    'query' => industrial::find(),
	    'pagination'=>['pageSize'=>20]),
	]);

        return $this->render('index', ['dataProvider'=>$dataProvider]);
    }
}


and your view like this:

<?php
use yii\helpers\Html;
use kartik\export\ExportMenu;
use kartik\grid\GridView;

$gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
    'id',
    'name',
    [
        'attribute'=>'Name',
        'label'=>'Name',
        'vAlign'=>'middle',
        'width'=>'190px',
        'value'=>function ($model, $key, $index, $widget) { 
            return Html::a($model->Name, '#', []);
        },
        'format'=>'raw'
    ],
    'Name',
    'Location',
    'Telephone',
    
];

?>

<h1>Industrial Companies</h1>

<?= ExportMenu::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'fontAwesome' => true,
    'dropdownOptions' => [
        'label' => 'Export All',
        'class' => 'btn btn-default'
    ]
]) ?>

<hr>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'export' => [
        'fontAwesome' => true,
    ]
]); ?>

1

#4 User is offline   R Hamzeh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 05-June 14

Posted 26 February 2015 - 08:08 AM

View Postbazantj, on 26 February 2015 - 06:05 AM, said:

I am not sure I understand what you are trying to achive.

Still I would suggest to update your controller like this:

<?php

namespace app\controllers;


use yii\web\Controller;
use app\models\industrial;
use yii\data\ActiveDataProvider;

class IndustrialController extends Controller
{
    public function actionIndex()
    {
        $dataProvider=new ActiveDataProvider([
	    'query' => industrial::find(),
	    'pagination'=>['pageSize'=>20]),
	]);

        return $this->render('index', ['dataProvider'=>$dataProvider]);
    }
}


and your view like this:

<?php
use yii\helpers\Html;
use kartik\export\ExportMenu;
use kartik\grid\GridView;

$gridColumns = [
    ['class' => 'yii\grid\SerialColumn'],
    'id',
    'name',
    [
        'attribute'=>'Name',
        'label'=>'Name',
        'vAlign'=>'middle',
        'width'=>'190px',
        'value'=>function ($model, $key, $index, $widget) { 
            return Html::a($model->Name, '#', []);
        },
        'format'=>'raw'
    ],
    'Name',
    'Location',
    'Telephone',
    
];

?>

<h1>Industrial Companies</h1>

<?= ExportMenu::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'fontAwesome' => true,
    'dropdownOptions' => [
        'label' => 'Export All',
        'class' => 'btn btn-default'
    ]
]) ?>

<hr>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => $gridColumns,
    'export' => [
        'fontAwesome' => true,
    ]
]); ?>



It worked thanks :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users