Magento 2 Write to CSV within ControllerUnit Test for overwrite collection class in magento2CSV import not working - Need AssistanceI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleMagento 2: How to override newsletter Subscriber modelMagento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.2.5: Overriding Admin Controller sales/orderMagento 2.3 Can't view module's front end page output?magento 2.2 trying to save multi select value in database
How to properly say asset/assets in German
13th chords on guitar
Single level file directory
Comment traduire « That screams X »
Can you actually break an FPGA by programming it wrong?
Put my student loan in parents’ second mortgage - help?
How did Lefschetz do mathematics without hands?
Will writing actual numbers instead of writing them with letters affect readership?
Why wasn't EBCDIC designed with contiguous alphanumeric characters?
Sharing referee/AE report online to point out a grievous error in refereeing
Grant dbcreator only for databases matching prefix
Can a nowhere continuous function have a connected graph?
How did researchers find articles before the Internet and the computer era?
Why do I need two parameters in an HTTP parameter pollution attack?
I need help with pasta
Reusable spacecraft: why still have fairings detach, instead of open/close?
How Do I Know When I am in Private Mode?
Is it okay to fade a human face just to create some space to place important content over it?
What kind of jet plane is this?
Is there reliable evidence that depleted uranium from the 1999 NATO bombing is causing cancer in Serbia?
Converting Geographic Coordinates into Lambert2008 coordinates
I just started should I accept a farewell lunch for a coworker I don't know?
Why would anyone even use a Portkey?
Copy group of files (Filename*) to backup (Filename*.bak)
Magento 2 Write to CSV within Controller
Unit Test for overwrite collection class in magento2CSV import not working - Need AssistanceI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleMagento 2: How to override newsletter Subscriber modelMagento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.2.5: Overriding Admin Controller sales/orderMagento 2.3 Can't view module's front end page output?magento 2.2 trying to save multi select value in database
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have the following code:
protected $_fileSystem;
protected $_directoryList;
public function __construct(
MagentoFrameworkFilesystem $fileSystem,
MagentoFrameworkAppFilesystemDirectoryList $directoryList
)
$this->_fileSystem = $fileSystem;
$this->_directoryList = $directoryList;
parent::__construct($context);
public function execute()
$this->writeToCSV();
private function writeToCSV()
try
$media = $this->_fileSystem->getDirectoryWrite($this->_directoryList::MEDIA);
$media->writeFile('text.txt', 'test');
catch(Exception $e)
echo($e->getMessage());
However, this doesn't seem to be writing anything to the text file that exists within the same folder as the controller.
magento2 controllers csv
add a comment |
I have the following code:
protected $_fileSystem;
protected $_directoryList;
public function __construct(
MagentoFrameworkFilesystem $fileSystem,
MagentoFrameworkAppFilesystemDirectoryList $directoryList
)
$this->_fileSystem = $fileSystem;
$this->_directoryList = $directoryList;
parent::__construct($context);
public function execute()
$this->writeToCSV();
private function writeToCSV()
try
$media = $this->_fileSystem->getDirectoryWrite($this->_directoryList::MEDIA);
$media->writeFile('text.txt', 'test');
catch(Exception $e)
echo($e->getMessage());
However, this doesn't seem to be writing anything to the text file that exists within the same folder as the controller.
magento2 controllers csv
add a comment |
I have the following code:
protected $_fileSystem;
protected $_directoryList;
public function __construct(
MagentoFrameworkFilesystem $fileSystem,
MagentoFrameworkAppFilesystemDirectoryList $directoryList
)
$this->_fileSystem = $fileSystem;
$this->_directoryList = $directoryList;
parent::__construct($context);
public function execute()
$this->writeToCSV();
private function writeToCSV()
try
$media = $this->_fileSystem->getDirectoryWrite($this->_directoryList::MEDIA);
$media->writeFile('text.txt', 'test');
catch(Exception $e)
echo($e->getMessage());
However, this doesn't seem to be writing anything to the text file that exists within the same folder as the controller.
magento2 controllers csv
I have the following code:
protected $_fileSystem;
protected $_directoryList;
public function __construct(
MagentoFrameworkFilesystem $fileSystem,
MagentoFrameworkAppFilesystemDirectoryList $directoryList
)
$this->_fileSystem = $fileSystem;
$this->_directoryList = $directoryList;
parent::__construct($context);
public function execute()
$this->writeToCSV();
private function writeToCSV()
try
$media = $this->_fileSystem->getDirectoryWrite($this->_directoryList::MEDIA);
$media->writeFile('text.txt', 'test');
catch(Exception $e)
echo($e->getMessage());
However, this doesn't seem to be writing anything to the text file that exists within the same folder as the controller.
magento2 controllers csv
magento2 controllers csv
asked Jan 18 at 11:26
A. FletcherA. Fletcher
9410 bronze badges
9410 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can write csv file using below way,
<?php
protected $filesystem;
protected $directoryList;
protected $csvProcessor;
public function __construct(
MagentoFrameworkFileCsv $csvProcessor,
MagentoFrameworkAppFilesystemDirectoryList $directoryList,
MagentoFrameworkFilesystem $filesystem
)
$this->filesystem = $filesystem;
$this->directoryList = $directoryList;
$this->csvProcessor = $csvProcessor;
function writeToCsv()
$fileDirectoryPath = $this->directoryList->getPath(MagentoFrameworkAppFilesystemDirectoryList::VAR_DIR);
if(!is_dir($fileDirectoryPath))
mkdir($fileDirectoryPath, 0777, true);
$fileName = 'export.csv';
$filePath = $fileDirectoryPath . '/' . $fileName;
$data = [];
/* pass data array to write in csv file */
$data[] = ['orderid' => '100001'];
$this->csvProcessor
->setEnclosure('"')
->setDelimiter(',')
->saveData($filePath, $data);
return true;
You can check your generated CSV file inside var folder
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258349%2fmagento-2-write-to-csv-within-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can write csv file using below way,
<?php
protected $filesystem;
protected $directoryList;
protected $csvProcessor;
public function __construct(
MagentoFrameworkFileCsv $csvProcessor,
MagentoFrameworkAppFilesystemDirectoryList $directoryList,
MagentoFrameworkFilesystem $filesystem
)
$this->filesystem = $filesystem;
$this->directoryList = $directoryList;
$this->csvProcessor = $csvProcessor;
function writeToCsv()
$fileDirectoryPath = $this->directoryList->getPath(MagentoFrameworkAppFilesystemDirectoryList::VAR_DIR);
if(!is_dir($fileDirectoryPath))
mkdir($fileDirectoryPath, 0777, true);
$fileName = 'export.csv';
$filePath = $fileDirectoryPath . '/' . $fileName;
$data = [];
/* pass data array to write in csv file */
$data[] = ['orderid' => '100001'];
$this->csvProcessor
->setEnclosure('"')
->setDelimiter(',')
->saveData($filePath, $data);
return true;
You can check your generated CSV file inside var folder
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
add a comment |
You can write csv file using below way,
<?php
protected $filesystem;
protected $directoryList;
protected $csvProcessor;
public function __construct(
MagentoFrameworkFileCsv $csvProcessor,
MagentoFrameworkAppFilesystemDirectoryList $directoryList,
MagentoFrameworkFilesystem $filesystem
)
$this->filesystem = $filesystem;
$this->directoryList = $directoryList;
$this->csvProcessor = $csvProcessor;
function writeToCsv()
$fileDirectoryPath = $this->directoryList->getPath(MagentoFrameworkAppFilesystemDirectoryList::VAR_DIR);
if(!is_dir($fileDirectoryPath))
mkdir($fileDirectoryPath, 0777, true);
$fileName = 'export.csv';
$filePath = $fileDirectoryPath . '/' . $fileName;
$data = [];
/* pass data array to write in csv file */
$data[] = ['orderid' => '100001'];
$this->csvProcessor
->setEnclosure('"')
->setDelimiter(',')
->saveData($filePath, $data);
return true;
You can check your generated CSV file inside var folder
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
add a comment |
You can write csv file using below way,
<?php
protected $filesystem;
protected $directoryList;
protected $csvProcessor;
public function __construct(
MagentoFrameworkFileCsv $csvProcessor,
MagentoFrameworkAppFilesystemDirectoryList $directoryList,
MagentoFrameworkFilesystem $filesystem
)
$this->filesystem = $filesystem;
$this->directoryList = $directoryList;
$this->csvProcessor = $csvProcessor;
function writeToCsv()
$fileDirectoryPath = $this->directoryList->getPath(MagentoFrameworkAppFilesystemDirectoryList::VAR_DIR);
if(!is_dir($fileDirectoryPath))
mkdir($fileDirectoryPath, 0777, true);
$fileName = 'export.csv';
$filePath = $fileDirectoryPath . '/' . $fileName;
$data = [];
/* pass data array to write in csv file */
$data[] = ['orderid' => '100001'];
$this->csvProcessor
->setEnclosure('"')
->setDelimiter(',')
->saveData($filePath, $data);
return true;
You can check your generated CSV file inside var folder
You can write csv file using below way,
<?php
protected $filesystem;
protected $directoryList;
protected $csvProcessor;
public function __construct(
MagentoFrameworkFileCsv $csvProcessor,
MagentoFrameworkAppFilesystemDirectoryList $directoryList,
MagentoFrameworkFilesystem $filesystem
)
$this->filesystem = $filesystem;
$this->directoryList = $directoryList;
$this->csvProcessor = $csvProcessor;
function writeToCsv()
$fileDirectoryPath = $this->directoryList->getPath(MagentoFrameworkAppFilesystemDirectoryList::VAR_DIR);
if(!is_dir($fileDirectoryPath))
mkdir($fileDirectoryPath, 0777, true);
$fileName = 'export.csv';
$filePath = $fileDirectoryPath . '/' . $fileName;
$data = [];
/* pass data array to write in csv file */
$data[] = ['orderid' => '100001'];
$this->csvProcessor
->setEnclosure('"')
->setDelimiter(',')
->saveData($filePath, $data);
return true;
You can check your generated CSV file inside var folder
edited Jun 20 at 6:54
Khushbu
30713 bronze badges
30713 bronze badges
answered Jan 18 at 11:30
Rakesh DongaRakesh Donga
2,9456 silver badges21 bronze badges
2,9456 silver badges21 bronze badges
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
add a comment |
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
I'll give it a whirl. Thanks again Rakesh, always super fast at answering questions.
– A. Fletcher
Jan 18 at 11:32
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
Just a quick question about the directory path. Do I carry on from MagentoFrameworkApp as though I was in the app folder? So in my case codecompanymodule?
– A. Fletcher
Jan 18 at 11:38
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
my path is var directory you can set your path
– Rakesh Donga
Jan 18 at 11:42
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f258349%2fmagento-2-write-to-csv-within-controller%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown