I am working with Symfony2 framework, I am fetching data from DB through Doctrine, now I want to save query result in CSV format.
my Doctrine query result array structure:
array('id' => '1', 'firstname' => 'Paul', 'surname' => 'White', 'email' => 'paul_white@gmail.com')
my code:
public function dataToCSV($records)
{
$cavPath = 'Test\TestBundle\Resourceseports\test2.csv';
$csvh = fopen($cavPath, 'w');
foreach ($records as $record)
{
fputcsv($csvh, $record);
}
fclose($csvh);
}
the $records param picked ups the query result.
The problem is i get no errors but at the same time i cannot see the csv file being stored in given path 'Test\TestBundle\Resourceseports\test2.csv'.
Maybe there is a stable Symfony bundle that can do all this for me...?
OK well I got a answer for my question so:
Because I am working unix system (Mac os) my slashes were the wrong way plus the SYmfony2 default directory is web so i had go back one directory back.
solution
..src/Test/TestBundle/Resources/reports/test2.csv