PHP code example of joaomfrebelo / reports_4_php

1. Go to this page and download the library: Download joaomfrebelo/reports_4_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

joaomfrebelo / reports_4_php example snippets


use Rebelo\Reports\Report\Datasource\Database;
use Rebelo\Test\Reports\Report\Parameter\Parameter;
use Rebelo\Test\Reports\Report\Parameter\Type;
use Rebelo\Reports\Report\JasperFile;
use Rebelo\Reports\Report\Pdf;

$ds = new Database();
$ds->setConnectionString("jdbc:mysql://localhost/sakila");
$ds->setDriver("com.mysql.jdbc.Driver");
$ds->setUser("user");
$ds->setPassword("password");

$parameter = new Parameter(new Type(Type::P_STRING),"parameter name", "parameter value");

$jf = new JasperFile("/path/to/report.jasper", 1);

$pdf = new Pdf();
$pdf->setDatasource($ds);
$pdf->setJasperFile($jf);

$report = new Report();

// Using PChouse reports API

$pdfBase64Encoded = $report->invokeApi($pdf);

// Using Rebelo reports_cli

$pdf->setOutputfile("/path/to/outfile.pdf");
$result = $report->generate($pdf);

if($result->getCode() == 0){
    // exported ok
    // pdf is in /path/to/outfile.pdf
}else{
    // see exitcode
    // see messages with  $result->getMessages();
}


bash
$ composer