[Flow] export to .csv
Steffen Wickham
steffen at gaming-inc.de
Tue Apr 28 17:10:13 CEST 2015
Okay, I'll have a look in my source when I'm home. Somewhere in my tool
I needed something similar and found a solution for it if I remember
correctly.
What kind of "special rows" are you talking about? I wrote some kind of
complex management tool but never used DQL, just the functions as you
already did.
You're welcome :)
Am 28.04.15 um 16:52 schrieb Andre Hohmann:
>
>
> Hallo Steffen,
>
> thank you. With "fputcsv($fp, $lines->toArray());" I get an error in the
> log:
>
> PHP Fatal error: Call to undefined method
> itoopatcDomainModelMitglied::toArray() in /var/www/apps/flow...
>
> Maybe I´ll try it with arbitrary DQL in the Repository...(at the end I
> want to export only special rows out of the table "Mitglied" as
> .csv-file)...? Or is there a simple opportunity to select only special
> rows of the class/table "Mitglied"?
>
> Thank you for the other hints, too!!
>
> ---
>
> Mit freundlichen Grüssen
>
> Andre Hohmann
>
> Am 2015-04-28 15:14, schrieb Steffen Wickham:
>
>> 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!
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow [1]
>
>
> Links:
> ------
> [1] http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
>
>
> ---------------------------------------------------------------------------------------------
>
> http://www.andre-hohmann.net
>
>
> Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren und die unbefugte Weitergabe dieser E-Mail sind nicht gestattet.
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list