KoolReport's Forum

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

Relative vs Absolute Path Issue in Report Development #2145

Open John Busse opened this topic on on Jun 15, 2021 - 1 comments

John Busse commented on Jun 15, 2021

I am trying to create a report that operates via two different URLs in order to embed a report within a separate application.

URL 1 (Working): https://reports.testdomain.com/finance/profit_and_loss/index.php URL 2 (Not Working): https://testdomain.com/reports/finance/profit_and_loss/index.php

Absolute path on disk: /data/websites/reporting_system/live/finance/profit_and_loss/

A symbolic link residing in: /data/websites/another_system/live/reports which points to: /data/websites/reporting_system/live/

The goal is to have all of the reports for every system located in the same place (reporting server). I would like to have the symbolic links enable connection to all of the reports vis their respective URLs.

Response of the getcwd() function within the MyReport.php file: data/websites/another_system/live

From within the koolreport/core/src/core/ResourceManager.php file (line 134), dumping of the $assets array produces the following:

array(2) {

["path"]=> string(44) "/data/websites/another_system/live/koolreport_assets" 
["url"]=> string(44) "/data/websites/another_system/live/koolreport_assets" 

}

I can live with the files residing in the /data/websites/another_system/live/koolreport_assets folder, however that is not optimal. I would prefer the assets folder reside as a subfolder of the actual report (ie: /data/websites/another_system/live/finance/profit_and_loss/koolreport_assets) rather then at the top level. Getting the report to work is more important at this time.

When the report attempts to run, the following errors appear via the page Inspector within Firefox: GET https://testdomain.com/data/websites/another_system/live/koolreport_assets/3409401219/KoolReport.js Uncaught SyntaxError: missing ) after argument list

That path will never work. It should be at least https://testdomain.com/koolreport_assets/3409401219/KoolReport.js

index.php

<?php

require_once "../../koolreport/core/autoload.php"; require_once "MyReport.php";

$report = new MyReport; $report->run()->render();

MyReport.php

<?php

echo getcwd(); class MyReport extends \koolreport\KoolReport {

}

MyReport.view.php

<?php

use \koolreport\widgets\google\BarChart;

$category_amount = array(
    array("category"=>"Books","sale"=>32000,"cost"=>20000,"profit"=>12000),
    array("category"=>"Accessories","sale"=>43000,"cost"=>36000,"profit"=>7000),
    array("category"=>"Phones","sale"=>54000,"cost"=>39000,"profit"=>15000),
    array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
    array("category"=>"Others","sale"=>12000,"cost"=>6000,"profit"=>6000),
);

$category_sale_month = array(
    array("category"=>"Books","January"=>32000,"February"=>20000,"March"=>12000),
    array("category"=>"Accessories","January"=>43000,"February"=>36000,"March"=>7000),
    array("category"=>"Phones","January"=>54000,"February"=>39000,"March"=>15000),
    array("category"=>"Others","January"=>12000,"February"=>6000,"March"=>6000),
);

?> <div class="report-content">

<div style="margin-bottom:50px;">
<?php
BarChart::create(array(
    "title"=>"Sale Report",
    "dataSource"=>$category_amount,
    "columns"=>array(
        "category",
        "sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
        "cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
        "profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
    )
));
?>
</div>
<div style="margin-bottom:50px;">
<?php
BarChart::create(array(
    "title"=>"Sale Report on Stack",
    "dataSource"=>$category_sale_month,
    "columns"=>array(
        "category",
        "January"=>array("label"=>"January","type"=>"number","prefix"=>"$"),
        "February"=>array("label"=>"February","type"=>"number","prefix"=>"$"),
        "March"=>array("label"=>"March","type"=>"number","prefix"=>"$"),
    ),
    "options"=>array(
        "isStacked"=>true
    )
));
?>
</div>

</div>

Any assistance with correctig the pathing would be greatly helpful.

Sebastian Morales commented on Jun 16, 2021

John, since working with both symbolic links and assets management is not always perfect automatically pls try to set the report's assets setting explicitly as documented in this link:

https://www.koolreport.com/docs/architecture/assets_settings/#overview

class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            ...
            "assets"=>array(
                "path"=>" /data/websites/another_system/live/finance/profit_and_loss/koolreport_assets", //this directory must be created beforehand
                "url"=>"/finance/profit_and_loss/koolreport_assets", //absolute or relative url to the assets directory
            )
        );
    }
}

The idea is that assets' path is the directory we want to copy our resources (js, css, img, etc) to and assets' url is the link (minus the domain name) from which those resources could be access with browsers. Rgds,

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