Forums

Export to CSV - problem

Fredolino 30 Nov, 2019
Hi,

I have a CSV-Action with
Data provider: {var:read_data.[n].export}
Action: Download
and in Titles:
datum:Datum
beobachtung:Beobachtung
mtb_id:MTB
...

In the read_data-Function 6 connected tables with models
Select type: All matching record
Where conditions:
user_id = {user:id} Use
Fields to retrieve:
Beobs.datum:export.datum
Beobs.beobachtung:export.beobachtung
Beo-Ort.mtb_id:export.mtb_id
...
This is an extra fields list: yes

I get a warning message. What is the problem?

F.
Proximate 30 Nov, 2019
Can you post the debug of the page where the CSV will be created?
Fredolino 30 Nov, 2019
Hi,
I've created a PHP action (csv_data) with code: return [$ this-> data];
In the CSV action (csv1) in the data provider: {var: csv_data}
As Action: Store and download
Storage path: {path: root} /csv/export.csv
The warning message is gone, but I only have the column headings in the CSV file.
Where exactly do I have to insert the debug?
Proximate 30 Nov, 2019
just add {debug:}
at the end of your event (page) where the csv will be created (like other views or functions)
Fredolino 30 Nov, 2019
Under the View-Tab i have a table "beobachtungen_list" and a Task Button "export_csv_button" with Event "export".
Under Events-Tab:

index
<div id="view_articles_list" >
{fn:read_beobachtungen}
{view:beobachtungen_list}
</div>
{view:export_csv_button}
<div class="ui segment">
{view:beobachtungen_paginator}
</div>

export
{fn:csv1}
{debug:csv1}
{fn:redirect5-off}

The debugger is not displayed.
If the debugger is in index-event, then everything from the connected tables will be displayed to me in read_views.
Fredolino 04 Dec, 2019
Hi,
this is my new stand:

I can not save the data from the "Table list" to a CSV file.

The frontend shows my table list. The content should be exported but something else is in the CSV file (screen1).

In the CSV action (csv_export), this is in the data provider: {var:read_observations.0}.
I do not know how the data provider has to be right.

This is my read data action (screen2).

What am I doing wrong?

healyhatman 04 Dec, 2019
The data provider should be {var:read_beobachtungen.[n].export}
Fredolino 05 Dec, 2019
I've already tried that.

But then I get the warning:
"warning: fputcsv () expects parameter 2 to be array null given in ..."

I also tested a php action afterwards with the content:
return [$this->data];
or
return["datum" => $this->data("Datum"), "Beobachtung" => $this->data("beobachtung")];
that only showed me the column headings and no other content ....
Fredolino 05 Dec, 2019
the debugger:

Array
(
    [99b2] => 2899
    [84a67] => 4501
    [joomla_user_state] => logged_in
    [Itemid] => 942
    [option] => com_content
    [view] => article
    [id] => 15
    [export] =>
)
Array
(
    [read_beobachtungen] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Beob`.`beof_id` AS `Beob.beof_id`, `Beob`.`user_id` AS `Beob.user_id`, `Beob`.`beo_id` AS `Beob.beo_id`,
   ......
              )
            [var] => Array
                (
                    [0] => Array
                        (
                            [Beob] => Array
                                (
                                    [beof_id] => 2
                                    [user_id] => 909
                                    [beo_id] => 4
                                    [datum] => 1939-04-01
                                    [beobachtung] => Am Tag
                                    [teilnehmer] => Anton Hinkel
                                    [datenweitergabe] => 0
                                    [created] => 2019-09-09 19:24:50
                                    [modified] =>
                                )
                            [Melder] => Array
                                (
                                    [id] => 909
                                    [name] => Fred O
                                    [username] => admin
                                    [email] => nat@so.de
        .....
Fredolino 05 Dec, 2019
i can not edit my post….grrr...
Fredolino 05 Dec, 2019
Array
(
    [99b2] => 2899
    [84a67] => 4501
    [joomla_user_state] => logged_in
    [Itemid] => 942
    [option] => com_content
    [view] => article
    [id] => 15
    [export] =>
)
Array
(
    [read_beobachtungen] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Beob`.`beof_id` AS `Beob.beof_id`, `Beob`.`user_id` AS `Beob.user_id`, `Beob`.`beo_id` AS `Beob.beo_id`,
   ......
              )
            [var] => Array
                (
                    [0] => Array
                        (
                            [Beob] => Array
                                (
                                    [beof_id] => 2
                                    [user_id] => 909
                                    [beo_id] => 4
                                    [datum] => 1939-04-01
                                    [beobachtung] => Am Tag
                                    [teilnehmer] => Anton Hinkel
                                    [datenweitergabe] => 0
                                    [created] => 2019-09-09 19:24:50
                                    [modified] =>
                                )
                            [Melder] => Array
                                (
                                    [id] => 909
                                    [name] => Fred O
                                    [username] => admin
                                    [email] => nat@so.de
        .....
Fredolino 05 Dec, 2019
with pdf...[file=12459]Unbenannt-1.pdf[/file]
Fredolino 05 Dec, 2019
Hi,

So with several tables, the csv function does not work
Only the content of a table is exported with a model.
if i want to export linked tables with multiple models then this will not work.
Only the content of an array is taken over.


F
healyhatman 06 Dec, 2019
You shouldn't have the "extra fields" box ticked
And in fields to retrieve you may need to also include all the fields you will be joining on - so if a second model needs column_a, make sure you're retrieving it.
Fredolino 06 Dec, 2019
Answer
It only works with a PHP action

$read = $this->get('read_beobachtungen');
foreach ($read as $key => $record)
{
$r['ID']  = $record['Beob']['beo_id'];
.....
This topic is locked and no more replies can be posted.