PHP code example of vrtc / yii2-export

1. Go to this page and download the library: Download vrtc/yii2-export library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vrtc / yii2-export example snippets


// в файле настройки приложения (main.php - Advanced или web.php - Basic) добавляется класс в controllerMap
...
'controllerMap' => [
    'export' => 'vrtc\exportFile\controllers\ExportController'
],
'components' => [
    ...
],

...
class GeoCitySearch extends GeoCity
{
...
    // указываются свойства, которые нужно выводить в файлы
    public function exportFields()
    {
        return [
            'id' => function ($model) {
                /* @var $model User */
                return $model->id;
            },
            'name_ru',
            'region_id' => function ($model) {
                /* @var $model GeoCity */
                if (isset($model->region->name_ru)) {
                    return $model->region->name_ru;
                }
                return false;
            },
            'lat',
            'lon'
        ];
    }
...
}

...
    // cоздается стандартное действие для вывода данных
    public function actionExportFile()
    {
        $searchModel = new GeoCitySearch();
        $dataProvider = $searchModel->search(\Yii::$app->request->queryParams);

        return $this->render('export-file', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
...

use vrtc\exportFile\ExportFile;
use yii\grid\GridView;
/* @var $searchModel \common\models\GeoCitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

// минимальные настройки
echo ExportFile::widget([
        'model'             => 'common\models\GeoCitySearch',   // путь к модели
        'searchAttributes'  => $searchModel,                    // фильтр
]) 

use vrtc\exportFile\ExportFile;
use yii\grid\GridView;
/* @var $searchModel \common\models\GeoCitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

// максимальные настройки
echo \vrtc\exportFile\ExportFile::widget([
        'model' => WebProxyFrontendSearch::class,   // путь к модели
        'queryParams' => Yii::$app->request->queryParams,
        'getAll' => true,
        'xls' => [
            'buttonOption' => [
                'class' => 'btn btn--blue btn-proxy'
            ],
            'tagOption' => [
              'class' => 'export-form',
            ],
            'tag' => 'div'
        ],
        'txt' => [
            'buttonOption' => [
                'class' => 'btn btn--blue btn-proxy'
            ],
            'tagOption' => [
                'class' => 'export-form'
            ],
            'tag' => 'div',
            '

php composer.phar