Showing a Report in the Viewer in an HTML template using PHP variables
Our sample projects and report templates can help you learn the basics of working with our products.Instead of printing directly, the viewer's HTML can be captured into PHP variables and echoed wherever you need — handy for templating engines.
Supplying values. Load the template, resolve its variables, assign the application values, and render or display the updated report.
Supplying values. Load the template, resolve its variables, assign the application values, and render or display the updated report.
<?php
require_once '../vendor/autoload.php';
use Stimulsoft\Report\StiReport;
use Stimulsoft\Viewer\StiViewer;
// Creating a viewer object and set the necessary javascript options
$viewer = new StiViewer();
$viewer->javascript->relativePath = '../';
// Processing the request and, if successful, immediately printing the result
$viewer->process();
// Creating a report object
$report = new StiReport();
// Loading a report by URL
// This method does not load the report object on the server side, it only generates the necessary JavaScript code
// The report will be loaded into a JavaScript object on the client side
$report->loadFile('../reports/SimpleList.mrt');
// Assigning a report object to the viewer
$viewer->report = $report;
// Getting the necessary JavaScript code and visual HTML part of the viewer
$js = $viewer->javascript->getHtml();
$html = $viewer->getHtml();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
<title>Showing a Report in the Viewer in an HTML template using PHP variables</title>
<style>
html, body {
font-family: sans-serif;
}
</style>
<?php
// Printing the necessary JavaScript code of the viewer
echo $js;
?>
</head>
<body>
<h2>Showing a Report in the Viewer in an HTML template using PHP variables</h2>
<hr>
<?php
// Printing the visual HTML part of the viewer
echo $html;
?>
</body>
</html>process()— handles the viewer's server-side requests before any HTML is produced.javascript->getHtml()— returns the script markup as a string instead of printing it.getHtml()— returns the viewer body markup as a string.echo $js / echo $html— insert the captured strings anywhere in your template or templating engine.
getHtml() returns the markup as a string rather than printing it, so you can store the scripts and the viewer body in variables and insert them into any layout or template system.