Skip to content

PHP Generate Reports

Peter Gill edited this page Jan 13, 2014 · 15 revisions

Currently the RdlCmd php wrapper code is not bundled in a release. You must download a copy from master. To view online go to https://github.com/majorsilence/My-FyiReporting/tree/master/LanguageWrappers/php. Examples of using php is in the Examples folder in the above link.

Requires php 5.3 or newer.

Details

report.php

  • Namespace: MyFyiReporting
  • Class: Report(path_to_rdl_file)
  • Functions:
    • export(export_type, save_path)
      • export_type: "pdf", "csv", "xslx", "xml", "rtf", "tif", "html"
        • If type does not match it will default to pdf
      • save_path: the directory path and file name that will be generated
    • export_to_memory(export_type)
      • export type: "pdf", "csv", "xslx", "xml", "rtf", "tif", "html"
      • If type does not match it will default to pdf

config.php

Set the paths to mono, rdlcmd, and set if on windows or not.

Requires using mono on linux or .net on windows.

You must change the values in this file to match what you need.

Examples

Example of calling a basic report and generating the file hello2.pdf.

<?php
require_once("../report.php");

$rpt = new \MyFyiReporting\Report("C:\\path\\to\\SimpleTest1.rdl");
$rpt->export("pdf", "C:\\output\path\hello2.pdf");

?>

Example generating a report that has a parameter. Multiple parameters can be added using the set_parameter function. This example generates the file hello.pdf.

<?php
require_once("../report.php");

$rpt = new \MyFyiReporting\Report('C:\\path\\to\\SimpleTestConnectionString.rdl');
$rpt->set_parameter("ConnectionString", 'Data Source=C:\\path\\to\\SqliteDatabaseFile.db;Version=3;Pooling=True;Max Pool Size=100;');
$rpt->export("pdf", "C:\\path\\to\\hello3.pdf");
?>

This example generates a report and loads it into memory using the export_to_memory function. It then sends it to the browser to view or download.

<?php
require_once("../report.php");

$rpt = new \MyFyiReporting\Report("C:\\path\\to\\SimpleTest1.rdl");
$data = $rpt->export_to_memory("pdf");

header("Content-type: application/octet-stream"); 
header("Content-disposition: attachment; filename=YourFileName2.pdf");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
ob_clean();
flush();

echo $data;
?>