I am trying to display CSV data to array or something as an output using Zend Framework 2
I have created "hello world" module and the controller calls works fine.
CSV File location is data/csv/Foo.csv
Below is my controller:
public function indexAction()
{
$filename = 'data/csv/Foo.csv';
$useFirstRecordAsHeader = true;
$delimiter = ',';
$enclosure = '"';
$escape = '\\';
$this->file = new SplFileObject($filename);
$this->file->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
$this->file->setCsvControl($delimiter, $enclosure, $escape);
$this->useFirstRecordAsHeader = $useFirstRecordAsHeader;
return $this;
}
But right now I am getting the error:
SplFileObject::__construct(csv/Foo.csv): failed to open stream: No such file or directory
My CSV file is in the same folder controller/csv/Foo.csv
How to read a CSV file content and display as output array or any other format? I want to do it using Zend Framework 2 only.