src/ngrest/base/Api.php
public function actionExport()
    {
        $this->checkAccess('export');
        
        $header = Yii::$app->request->getBodyParam('header', 1);
        $type = Yii::$app->request->getBodyParam('type');
        $attributes = Yii::$app->request->getBodyParam('attributes', []);
        $fields = ArrayHelper::getColumn($attributes, 'value');
        
        switch (strtolower($type)) {
            case "csv":
                $mime = 'application/csv';
                $extension = 'csv';
                break;
            case "xlsx":
                $mime = 'application/vnd.ms-excel';
                $extension = 'xlsx';
                break;
        }
        
        $query = $this->prepareListQuery()->select($fields);
        $tempData = ExportHelper::$type($query, $fields, (bool) $header);
        
        $key = uniqid('ngrestexport', true);
        
        $store = FileHelper::writeFile('@runtime/'.$key.'.tmp', $tempData);
        
        $menu = Yii::$app->adminmenu->getApiDetail($this->model->ngRestApiEndpoint());
        
        $route = $menu['route'];
        $route = str_replace("/index", "/export-download", $route);
        
        if ($store) {
            Yii::$app->session->set('tempNgRestFileName', Inflector::slug($this->model->tableName())  . '-export-'.date("Y-m-d-H-i").'.' . $extension);
            Yii::$app->session->set('tempNgRestFileMime', $mime);
            Yii::$app->session->set('tempNgRestFileKey', $key);

            $url = Url::toRoute(['/'.$route], true);
            $param = http_build_query(['key' => base64_encode($key), 'time' => time()]);

            if (StringHelper::contains('?', $url)) {
                $route = $url . "&" . $param;
            } else {
                $route = $url . "?" . $param;
            }
            return [
                'url' => $route,
            ];
        }
        
        throw new ErrorException("Unable to write the temporary file. Make sure the runtime folder is writeable.");
    }
public function actionExport()
    {
        $this->checkAccess('export');
        
        $header = Yii::$app->request->getBodyParam('header', 1);
        $type = Yii::$app->request->getBodyParam('type');
        $attributes = Yii::$app->request->getBodyParam('attributes', []);
        $fields = ArrayHelper::getColumn($attributes, 'value');
        
        switch (strtolower($type)) {
            case "csv":
                $mime = 'application/csv';
                $extension = 'csv';
                break;
            case "xlsx":
                $mime = 'application/vnd.ms-excel';
                $extension = 'xlsx';
                break;
        }
        
        $query = $this->prepareListQuery()->select($fields);
        $tempData = ExportHelper::$type($query, $fields, (bool) $header);
        
        $key = uniqid('ngrestexport', true);
        
        $store = FileHelper::writeFile('@runtime/'.$key.'.tmp', $tempData);
        
        $menu = Yii::$app->adminmenu->getApiDetail($this->model->ngRestApiEndpoint());
        
        $route = $menu['route'];
        $route = str_replace("/index", "/export-download", $route);
        
        if ($store) {
            Yii::$app->session->set('tempNgRestFileName', Inflector::slug($this->model->tableName())  . '-export-'.date("Y-m-d-H-i").'.' . $extension);
            Yii::$app->session->set('tempNgRestFileMime', $mime);
            Yii::$app->session->set('tempNgRestFileKey', $key);

            $url = Url::toRoute(['/'.$route], true);
            $param = http_build_query(['key' => base64_encode($key), 'time' => time()]);

            if (StringHelper::contains('?', $url)) {
                $route = $url . "&" . $param;
            } else {
                $route = $url . "?" . $param;
            }
            return [
                'url' => $route,
            ];
        }
        
        throw new ErrorException("Unable to write the temporary file. Make sure the runtime folder is writeable.");
    }
public function actionExport ( ) { $ this -> checkAccess ( 'export' ) ; $ header = Yii :: $ app -> request -> getBodyParam ( 'header' , 1 ) ; $ type = Yii :: $ app -> request -> getBodyParam ( 'type' ) ; $ attributes = Yii :: $ app -> request -> getBodyParam ( 'attributes' , [ ] ) ; $ fields = ArrayHelper :: getColumn ( $ attributes , 'value' ) ; switch ( strtolower ( $ type ) ) { case "csv" : $ mime = 'application/csv' ; $ extension = 'csv' ; break ; case "xlsx" : $ mime = 'application/vnd.ms-excel' ; $ extension = 'xlsx' ; break ; } $ query = $ this -> prepareListQuery ( ) -> select ( $ fields ) ; $ tempData = ExportHelper :: $ type ( $ query , $ fields , ( bool ) $ header ) ; $ key = uniqid ( 'ngrestexport' , true ) ; $ store = FileHelper :: writeFile ( '@runtime/' . $ key . '.tmp' , $ tempData ) ; $ menu = Yii :: $ app -> adminmenu -> getApiDetail ( $ this -> model -> ngRestApiEndpoint ( ) ) ; $ route = $ menu [ 'route' ] ; $ route = str_replace ( "/index" , "/export-download" , $ route ) ; if ( $ store ) { Yii :: $ app -> session -> set ( 'tempNgRestFileName' , Inflector :: slug ( $ this -> model -> tableName ( ) ) . '-export-' . date ( "Y-m-d-H-i" ) . '.' . $ extension ) ; Yii :: $ app -> session -> set ( 'tempNgRestFileMime' , $ mime ) ; Yii :: $ app -> session -> set ( 'tempNgRestFileKey' , $ key ) ; $ url = Url :: toRoute ( [ '/' . $ route ] , true ) ; $ param = http_build_query ( [ 'key' => base64_encode ( $ key ) , 'time' => time ( ) ] ) ; if ( StringHelper :: contains ( '?' , $ url ) ) { $ route = $ url . "&" . $ param ; } else { $ route = $ url . "?" . $ param ; } return [ 'url' => $ route , ] ; } throw new ErrorException ( "Unable to write the temporary file. Make sure the runtime folder is writeable." ) ; }
Export the Data into a temp CSV.

@return array
@throws ErrorException
Export the Data into a temp CSV .