Provide the data source (GRW for PHP)

You have used the Business Application Modeler to generate your data source library. You now need to integrate this library into your existing application.

Each of the demo applications that highlight a generated data source include an application node named RunReportFromApp. This node includes code that provides a working example of how to use the data source generated by the Business Application Modeler in your bespoke applications. At a high level, the application does three things:
  • Establishes a connection.
  • Creates a report.
  • Views the report.

Establish a connection

For this application, the connection creates a database connection to the officestore SQLite database. The details for the connection are hard-coded in the sample application.

Create a report

Before looking at the code that specifically creates the report, examine the code that starts the sample application:
set_include_path(get_include_path().PATH_SEPARATOR.getenv("PHPINCLUDEDIR"));
require_once 'libfourjsreportruntime.php';
require_once getenv("GSTUSERSAMPLESDIR"). "/Reports/BAMPhp/src/OrderReport.php";

Notice that two .php files are required: libfourjsreportruntime.php and the .php file that references the generated data source, which is OrderReport.php in this example.

With the data source object identified, look for the createOrderReportPDF method in the PHP sample application.

  1. Configure the report.

    In this example, the report is configured to be output to PDF.

    // Configure the report
    $greRunnerObj = new FourjsReportRuntime($reportDesignFileName, "OrderReport\OrderReport");
    $greRunnerObj->configureDistributedProcessing("127.0.0.1",7000);
    $greRunnerObj->selectDevice('PDF');
    $greRunnerObj->selectPreview(false);
    $greRunnerObj->setOutputFileName($reportFileName);
  2. Instantiate the data source object from the data source library.
    // Run the report
    $reportData = new OrderReport\OrderReport($connection);
  3. Pass the object to the report engine for processing.
    $greRunnerObj->run($reportData->getMasterRecord());

View the report

The viewReport method opens and displays the created PDF file.

For PHP, the PDF displays on Windows® systems only. For Mac® or Linux, you must find the location of the generated PDF in the output (as seen in the Output view of Genero Studio), then open the file yourself.