Hi I am trying to get the csv file data and display that data in my view .
Below is my controller function :
public function indexAction()
{
$delimiter = ',';
$enclosure = '""';
$escape = '//';
$filename = 'data' . DIRECTORY_SEPARATOR . 'csv' . DIRECTORY_SEPARATOR . 'StoreDepartment.csv';;
$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 = true;
$response = $this->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', 'text/csv');
$contents = $this->file->fread($this->file->getSize());
$response->setContent($contents);
$views = new ViewModel(array('text'=>$response));
return $views;
}
I am getting all the data as csv. but i am getting below warning :
Warning: SplFileObject::setCsvControl(): escape must be a character
Also i want to convert this data into JSON or Array format is it possible ?
Main concept is i want to store this data into my database table. So what format is suitable to store data in database ? Please Help
How to resolve both the errors ?