KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

ToArray() seems to fail #1590

Open The O opened this topic on on Aug 20, 2020 - 5 comments

The O commented on Aug 20, 2020

In my singlepage report, setup section I have this

//preceding setup function, at top of class
public $val;

// within setup function
$this->src('config')
->query(/* some query that correctly returns 7 rows of 2 columns within phpmyadmin */ ")
->pipe($this->dataStore("checks"));

$this->val = sizeof( $this->dataStore("checks")->toArray() );

//within html I have an H1 with <?php echo $report->val; ?>

A zero shows up in the H1 rather than 7. Please note dataStore("checks") is correctly showing 7 items in a ChartCard. The above is just a trouble-shooting step I took.

This question is related to this: basically I am looking for an alternative to get a value since pop() removes it from the dataStore. Nevertheless, I need to know why above code is not returning an array.

David Winterburn commented on Aug 21, 2020

Which part of the report did you put this line in?

$this->val = sizeof( $this->dataStore("checks")->toArray() );

If it's in the setup() method, the datastore hasn't been populated yet so the result should be empty. Please put it in the part where the view is rendered. Let us know the result. Thanks!

KoolReport commented on Aug 21, 2020

At the time when setup() method is run, no data is piped yet, that's why datastore has no data. Here is the life cycle of report. In case you really need the data at setup(), for example, the data is essential to get another data, please let us know.

The O commented on Aug 22, 2020

Thanks. So what do I do in this scenario:

"In case you really need the data at setup(), for example, the data is essential to get another data, please let us know."

David Winterburn commented on Aug 24, 2020

Probably try this:

$this->src(..)
->pipe(...)
...//use the same pipes as for datastore "checks"
->pipe($this->dataStore('tmpChecks')
->requestDataSending();

$this->val = sizeof( $this->dataStore("tmpChecks")->toArray() );

Let us know how it works for you. Thanks!

The O commented on Aug 24, 2020

Let me understand this: so I need to create an extra (temporary) dataStore and use that? But what does requestDataSending() do and why is it not in the documentation?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None