KoolReport's Forum

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

Bemused by File tree structure not working as expected for Koolreports #379

Open Datagaard opened this topic on on Jul 17, 2018 - 20 comments

Datagaard commented on Jul 17, 2018

I am very new to Koolreports, and looks great, and have been able to create a report of sorts within my application.

What has me bemused is that for what ever reason, I can't seem to get the file structure reference correct within my application.

File structure is this:

RoomBookings\KoolReports\CRReports
RoomBookings\KoolReports\examples
RoomBookings\KoolReports\koolreport

From a php page in RoomBookings\KoolReports\CRReports\test.php I have

require_once 'KoolReports/koolreport/autoload.php';

Runs the report fine, displays records, but this path is really invalid with respect to the actual test.php page.

But this raises an error on the server:

PHP Fatal error:  require_once(): Failed opening required 'KoolReports/koolreport/autoload.php' 

When I attempt to export to PDF.

If I change the path to what I would have expected it to be:

require_once '../koolreport/autoload.php';

I also get the error:

PHP Fatal error:  require_once(): Failed opening required '../koolreport/autoload.php' on test.php, 

but then the pdf export works okay.

What have I missed.

Regards

KoolReport commented on Jul 17, 2018

Are you able to run our examples?

See from your folder structures this below require_once is correct:

// CRReports\test.php
require_once '../koolreport/autoload.php';

Datagaard commented on Jul 17, 2018

I have based my code on your examples such as the advanced input_and_export report.

The basic report sales_by_Customer I have, after changing the file paths to suit.

Regards

KoolReport commented on Jul 17, 2018

If you run our examples from "localhost/.../KoolReports/examples" then you browse an example, let say the first one, do you get the result like this.

Datagaard commented on Jul 17, 2018

Yep:

localhost/roombookings/koolreports/examples/reports/basic/sales_by_customer/

Datagaard commented on Jul 17, 2018

The advanced input_and_export gives me an error, but that is due to not having the database installed that the example uses. The require_once "../../../../koolreport/autoload.php"; is not giving me an error

KoolReport commented on Jul 17, 2018

So does the problem get solved?

Datagaard commented on Jul 17, 2018

Nope.

KoolReport commented on Jul 17, 2018

So what is the error showing now?

If the error is because of database missing, you may install database. Please find them in the "examples/databases" folder. The input_and_export example requires "automaker" database.

Datagaard commented on Jul 17, 2018

Here is the file structure within my project:

Now the sales_by_Customer example works okay:

<?php

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

use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;
use \koolreport\processes\CopyColumn;
use \koolreport\processes\OnlyColumn;

class SalesByCustomer extends \koolreport\KoolReport
{

  function settings()
  {

My code in the Conference Rooms folder doesn't work?

<?php
	ob_start();
	ini_set("display_errors",1);

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

	use \koolreport\processes\Group;
	use \koolreport\processes\Sort;
	use \koolreport\processes\Limit;
	use \koolreport\processes\CopyColumn;
	use \koolreport\processes\OnlyColumn;
	use \koolreport\processes\DateTimeFormat;
	use \koolreport\processes\CalculatedColumn;

class DailySummaryOfBookings extends \koolreport\KoolReport
{
  use \koolreport\clients\Bootstrap;
  use \koolreport\inputs\Bindable;
  use \koolreport\inputs\POSTBinding;
  use \koolreport\export\Exportable;
  

Error reported on the page with display errors: Warning: require_once(../../../../koolreport/autoload.php): failed to open stream: No such file or directory in C:\Apache24\htdocs\RoomBookings\KoolReports\examples\reports\basic\ConferenceRooms\DailySummaryOfBookings.php on line 7

Regards

Datagaard commented on Jul 17, 2018

Now if I change my code to use:

require_once "KoolReports/koolreport/autoload.php";

my report works, as I wouldn't expect.

but if I change the example code also to:

require_once "KoolReports/koolreport/autoload.php";

The example code doesn't as I would expect

KoolReport commented on Jul 17, 2018

Why don't just start fresh? Please do this:

In folder "KoolReports", create a folder name "samplereport", so folder structure will be like this

RoomBookings\KoolReports\koolreport
RoomBookings\KoolReports\samplereport

In the "samplereport" folder, create 3 following files:

SampleReport.php

<?php
require_once "../koolreport/autoload.php";
class SampleReport extends \koolreport\KoolReport
{

}

SampleReport.view.php

<html>
    <head>
        <title>Sample Report</title>
    </head>
    <body>
        <h1>It works</h1>
    </body>
</html>

and index.php

require_once "SampleReport.php";

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

Now please run "localhost/.../KoolReports/samplereport/index.php" .. tell me what you get?

Datagaard commented on Jul 17, 2018

I get "It works" showing

KoolReport commented on Jul 17, 2018

Awesome, now you have the structure to get start with, copying the samplereport folder and changing name for any new report you want to make. Keep adding code to the new report. Anything please let us know.

Datagaard commented on Jul 18, 2018

The issue still exists if I take my reports out of the KoolReports folder and move it up the directory tree

RoomBookings\reportindex.php

Code in reportindex references require_once "KoolReports/CRReports/DailySummaryOfBookings.php";

same if I move the sample example above to the RoomBookings folder

PHP Fatal error: require_once() failed opening required '../koolreport/autoload.php'

KoolReport commented on Jul 18, 2018

You mean if you copy the samplecode down to level "examples/reports/basic" and change the require_once path, it will not work?

Datagaard commented on Jul 18, 2018

No if I move the sample code UP two levels

Datagaard commented on Jul 18, 2018

Referencing folders with includes and requires is based on the parent owning calling php page.

KoolReport commented on Jul 18, 2018

I see, maybe because of PHP settings is different from system to system so you do this:

require_once dirname(__FILE__)."/../koolreport/autoload.php";
Datagaard commented on Jul 18, 2018

Great that did it.

Thanks

KoolReport commented on Jul 18, 2018

Awesome :)

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

None