[Flow] export to .csv

Steffen Wickham steffen at gaming-inc.de
Tue Apr 28 15:14:56 CEST 2015


Hallo Andre,

I'm not able to have a look in my IDE to prove if my following help is 
correct but in your foearch loop try to call fputcsv like this: 
fputcsv($fp, $lines->toArray());
When you are iterating through the results of your repository request, 
you get an ready to use object of the model. If it won't help I will 
have a look for the right method when I'm back home.

Beside that problem, is there any special case why you created a 
"findTennis" method for your repository? There is a magic function in 
the default Repository class which can do such simple filtering, so you 
don't need to recreate it.
To get the same result try the following code for "exportTennisAction":

public function exportTennisAction() {

  // find all mitglieder with abteilung Tennis
  $this->mitgliedRepository->setOrderings(array('name' =>\\TYPO3\\Flow\\Persistence\\Query\\Interface::ORDER_ASCENDING));
  $records = $this->mitgliedRepository->findByAbteilung('Tennis');

  $csvPath =
'/var/www/apps/flow/Packages/Application/ITOOP.Atc/Resources/Private/Export/test.csv';

  $fp = fopen($csvPath, 'w');

  foreach ($records as $lines) {
  fputcsv($fp, $lines);
  }
  fclose($fp);
}

All the best again,
Steffen

P.S.: There is a solution for not hardcode your filepath, too. But I 
can't tell you it until I'm back home.



Am 28.04.15 um 14:39 schrieb Andre Hohmann:
>   
>
> Hallo,
>
> I want to export the class Mitglied to a csv-file. In my
> MitgliedRepository I make a query like this:
>
> public function findTennis() {
>   $query = $this->createQuery();
>   $result = $query->matching($query->equals('abteilung', 'Tennis'))
>   ->setOrderings(array('name' =>
> TYPO3FlowPersistenceQueryInterface::ORDER_ASCENDING))
>   ->execute();
>   return $result;
>   }
>
> In my controller I tried this:
>
> public function exportTennisAction() {
>
>   // find all mitglieder with abteilung Tennis
>   $records = $this->mitgliedRepository->findTennis();
>
>   $csvPath =
> '/var/www/apps/flow/Packages/Application/ITOOP.Atc/Resources/Private/Export/test.csv';
>
>   $fp = fopen($csvPath, 'w');
>
>   foreach ($records as $lines) {
>   fputcsv($fp, $lines);
>   }
>   fclose($fp);
>   }
>
> When I call the exportTennisAction, I get the following:
>
> #1: WARNING: FPUTCSV() EXPECTS PARAMETER 2 TO BE ARRAY, OBJECT GIVEN IN
> /VAR/WWW/APPS/FLOW/DATA/TEMPORARY/DEVELOPMENT/CACHE/CODE/FLOW_OBJECT_CLASSES/ITOOP_ATC_CONTROLLER_MITGLIEDCONTROLLER.PHP
> LINE 492
>
> Line 492 is:
>
> fputcsv($fp, $lines);
>
> Do I have to format the output of $records to arrays? How should I do
> that?
>
> Thank you!
>



More information about the Flow mailing list