What is the difference between getcsv () and getcsvfile () methods in magento?

I am trying to export AdminHtml grids to CSV. I have two methods getCsv () and getCsvFile () to export the result grid to a CSV file. Could you tell me what is the difference between these two functions?

Method -1

$fileName = "filename.csv";
$content    = $this->getLayout()->createBlock('custom_modelue/adminhtml_report_grid')
            ->getCsv();
$this->_prepareDownloadResponse($fileName, $content);

Method -2

$fileName = "filename.csv";
$content    = $this->getLayout()->createBlock('custom_modelue/adminhtml_report_grid')
            ->getCsvFile();
$this->_prepareDownloadResponse($fileName, $content);

When I use the -1 method, filters are not applied to export CSV results. But in method -2, Filters are applied to the result set.

+4
source share
2 answers

The difference between getCsv () and getCsvFile () is below

get CsvFile() is 

     Retrieve a file container array by grid data as CSV

     Return array with keys type and value

     return array

getcsvFile used to export a grid to a csv system in magen for the system in most cases

  and getCsv() is 
    Retrieve Grid data as CSV
    and return string
0
source

, .

getCsv() Mage\Adminhtml\Block\Report\Grid.php

getCsvFile() Mage\Adminhtml\Block\Widget\Grid.php

+1

Source: https://habr.com/ru/post/1532114/


All Articles