KoolReport's Forum

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

Getting error on: Call to a member function source() on null #1156

Closed Peter Harari opened this topic on on Nov 14, 2019 - 6 comments

Peter Harari commented on Nov 14, 2019

Hi,

I'm trying to build a simple report with a table but I'm getting the following error:

Call to a member function source() on null (View: [path]/report.blade.php)

This is how I'm calling the report in the view(report.blade.php):

<?php 

        $report = new ListReport(array(
            "data" => $model->data,
            "columns" => $model->columns
        ));

        $report->run()->render();
        
?>

As you can see the data was already fetched from database and passed as an array, as well the columns.

The ListReport class:

<?php 

namespace App\Reports;

use \koolreport\widgets\koolphp\Table;

class ListReport extends BaseReport
{
    public function settings()
    {
        return array(
            "dataSources" => array(
                "data" => array(
                    "class" => '\koolreport\datasources\ArrayDataSource',
                    "data" => $this->params["data"],
                    "dataFormat" => "table",
                )
            )
        );
    }

    protected function setup()
    {
        $this
            ->src('data')
            ->pipe(Table::create(
                array(
                    "dataSource" => $this->params["data"],
                    "columns" => $this->params["columns"]
                )
            ));
    } 
}

And the BaseReport class:

<?php

namespace App\Reports;

use \koolreport\KoolReport;

class BaseReport extends KoolReport
{
    use \koolreport\export\Exportable;
}

The point here is that I don't call source() anywhere in my code, so it seems to be something internal. Maybe something I'm not setting properly.

I am following this example. Thanks in advance.

KoolReport commented on Nov 15, 2019

This part of your code has issue:

        $this
            ->src('data')
            ->pipe(Table::create(
                array(
                    "dataSource" => $this->params["data"],
                    "columns" => $this->params["columns"]
                )
            ));

You need to pipe data to a dataStore

        $this
            ->src('data')
            ->pipe($this->dataStore("result"));

And then you create a ListReport.view.php in the same folder with ListReport.php with following content:

<?php
\koolreport\widgets\koolphp\Table::create(array(
    "dataSource" => $this->dataStore("result"),
    "columns" => $this->params["columns"]
));
?>
Peter Harari commented on Nov 15, 2019

Ok, now I see what I have missed.

A question: Is that view with same name as the class a requirement?

Because I'm trying to build a dynamic list report which will be used for most of my app's grids. I'm talking about 70~80 lists and I don't want to create a file to each one of them. That's why I'm trying to use the same view and the same class for that, only passing different data.

Peter Harari commented on Nov 15, 2019

I managed to get the report with Table to work. I now want to export it to pdf. When I run:

$report->run()
            ->export('ListReport')
            ->pdf(array(
                "format" => "A4",
                "orientation" => "portrait",
                //"zoom" => 2
            ))
            ->toBrowser($model->headerTitle . ".pdf");

I get the following error:

Could not find phantomjs executed file in bin folder (View: /home/vagrant/tyto/resources/views/report.blade.php)

So I added phantomjs to composer(using this) and installed it successfully, but the error remains. The lib was installed at /bin of my project but guessing by the code that threw the exception, that is not the same location it should be. The code is like:

$this->phantomjs = realpath(dirname(__FILE__))."/bin/phantomjs";

That won't look for phantomjs in the /bin folder.

In the package I have used in the composer, there is a config for the bin location:

"config": {
      "bin-dir": "bin"
},

Which I presume that points to the mentioned /bin folder.

Any idea about what should I do?

Peter Harari commented on Nov 18, 2019

Hello, I changed the phantomjs package bin folder to vendor/koolreport/export/bin and the export module started to find the phantomjs.exe, but I got a new error in Handler.php:73:

Could not execute phantomjs

I gave the file a 755 permission:

I also logged $result content before line 71 and its value was null.

I'm not sure what to do next.

Update

This is the $command variable content:

/home/vagrant/tyto/vendor/koolreport/export/bin/phantomjs.exe --ignore-ssl-errors=true /home/vagrant/tyto/vendor/koolreport/export/pdf/pdf.js /tmp/5dd2920bb312f3.tmp /tmp/5dd2920bb31a14.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJwaGFudG9tanMiOiJcL2hvbWVcL3ZhZ3JhbnRcL3R5dG9cL2JpblwvcGhhbnRvbWpzIiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHA6XC9cL3R5dG86ODBcL3JlcG9ydCIsInJlc291cmNlV2FpdGluZyI6MTAwMH0=

I can't find 5dd2920bb31a14.pdf file inside /tmp folder. Can it be something with shell_exec() ? How can I check it and/or enable it ?

Update 2

shell_exec() seems to work as I tested with: echo shell_exec ("hostname"); and it displayed homestead correctly.

David Winterburn commented on Nov 19, 2019

Hi Peter,

Please find out what your php user is by opening a php page with this content:

<?php echo exec('whoami'); ?>

Then give the php user the executable right to the file phantomjs.exe

Peter Harari commented on Nov 25, 2019

Hello, David.

After all those days, I put that aside a little and worked with phantomjs copied in the vendor/koolreport/export/bin folder, which works when developing in my local machine.

In order to make it work with composer, I used(as mentioned in another post above) this package but I could not get it to work because of two problems:

  1. KoolReport only looks at vendor/koolreport/export/bin for PhantomJs and unless I missed some config, you can't change that. Looking at the package source code(on Handler.php), it points to that path, so you find yourself in a dead end;

  2. The phantomjs-installer installs the binary in vendor/bin as default and I tried to change it using it's paramter bin-dir, but that messed up all my Laravel app.

Facing those problems, the only elegant way I came with was to fork the github package into https://github.com/mhcgolds/phantomjs-installer, and changed its source code in order to work as KoolReports likes. That made Heroku install PhantomJS correctly in the deployment process.

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
solved

Export