One of the main enhancements in version 2023.1 is a significant update in our Reports.PHP and Dashboards.PHP. We have already written about this in more detail in our recent news. When switching to a new version of the products, we tried to keep the already written code as compatible as possible. However, for the products to work correctly, it will be necessary to make minor changes. Please read about this in the article.

Product Deployment

To use the product, you should download the ZIP archive of the product from the Downloads page of our website, unpack it, and copy the /PHP folder to your Web server. This folder contains a Web project with all the necessary files and resources for the product work and examples for working with the viewer and designer.

To install the product in an existing project, you should copy the /vendor folder from the /PHP folder to the root directory of the project or use the Composer dependency manager by executing the following console command:

composer require stimulsoft/reports-php

or

composer require stimulsoft/dashboards-php.

Now you can delete the following folders with resources and scripts from previous product versions in the root directory: /localization, /css, /scripts, /stimulsoft. Be careful if the specified folders additionally contain your project files, then delete only the files associated with our products.

Connecting Product Libraries

Previously, all PHP libraries of the product were located in the /stimulsoft folder, and to connect them, it was enough to install the dependency for the main product file:
<?php
	require_once 'stimulsoft/helper.php';
?>

In the updated product, we changed the product scripts location folder. This was necessary to implement support for the Composer package manager. Now all files are located in the /vendor folder in the root directory of the project. To automatically connect all dependencies, you should connect the PHP class loader, which will automatically do the rest of the work:
<?php
	require_once 'vendor/autoload.php';
?>

Connecting scripts

Previously, to enable product scripts, it was necessary to add the entire list in the <head> block, depending on the required components and capabilities:
<head>
	<script src="/scripts/stimulsoft.reports.js" type="text/javascript"></script>
	<script src="/scripts/stimulsoft.dashboards.js" type="text/javascript"></script>
	<script src="/scripts/stimulsoft.viewer.js" type="text/javascript"></script>
</head>

The work of the specified connection method is saved, but after loading the package using Composer, it is necessary to correct the paths to all product scripts:
<head>
	<script src="/vendor/stimulsoft/reports-php/scripts/stimulsoft.reports.js" type="text/javascript"></script>
	<script src="/vendor/stimulsoft/dashboards-php/scripts/stimulsoft.dashboards.js" type="text/javascript"></script>
	<script src="/vendor/stimulsoft/reports-php/scripts/stimulsoft.viewer.js" type="text/javascript"></script>
</head>

In the updated product, a particular PHP class was added for its deployment, and we recommend using this method. Now, for deployment, it is enough to place a few lines of PHP code in the <head> block in the place where the product scripts were added:
<head>
	<?php
		$js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Viewer);
		$js->renderHtml();
	?>
</head>

You can customize the deployment process using the available class options if necessary.

Event handler initialization

A special event handler sends data to the PHP server-side from component events. It consists of a JavaScript client-side and a PHP server-side. Previously, to initialize it on an HTML page, you had to add the following PHP code:
<?php
	StiHelper::init('handler.php', 30);
?>

This code has been replaced in the new version to match the rest of the PHP classes in the updated products. It is enough to add updated code instead of the old code, everything else should work as before:
<?php
	$handler = new \Stimulsoft\StiHandler();
	$handler->renderHtml();
?>

You can change the path to the event handler file and the response timeout from the server using the available class options if necessary.

Working with components

All code written previously for working with components should work without any problems. PHP classes have been added to the updated product to work with the main features of the components, which makes it easier to work with them using PHP code. Now, if necessary, you can replace JavaScript code with PHP code. For example, use the following code to work with the report viewer:
<script type="text/javascript">
	<?php
		$options = new \Stimulsoft\Viewer\StiViewerOptions();
		$options->appearance->fullScreenMode = true;
		$options->appearance->scrollbarsMode = true;

		$viewer = new \Stimulsoft\Viewer\StiViewer($options);

		$report = new \Stimulsoft\Report\StiReport();
		$report->loadFile('reports/SimpleList.mrt');
		$viewer->report = $report;

		$viewer->renderHtml('viewerContent');
	?>
</script>

Working with events

In the same way as components, all of their events will work without code changes. In the updated product, we have simplified working with events. Now to work with the event on the PHP server-side, you only need to indicate that the selected event will be processed. For example, to add an SQL data retrieval event, one line of code is enough:
<script type="text/javascript">
	<?php
		$viewer = new \Stimulsoft\Viewer\StiViewer($options);
		$viewer->onBeginProcessData = true;
		$viewer->renderHtml('viewerContent');
	?>
</script>

If it is necessary to pre-process the event on the JavaScript client-side, you should specify the function name for the event. All the rest will be done automatically:
<script type="text/javascript">
	<?php
		$viewer = new \Stimulsoft\Viewer\StiViewer($options);
		$viewer->onBeginProcessData = 'onBeginProcessData';
		$viewer->renderHtml('viewerContent');
	?>
	
	function onBeginProcessData(args) {
	}
</script>

Exporting a report

Previously, you had to write a relatively large block of JavaScript code to export a report. For example, you would add the following code to an HTML page to export a report to PDF:
var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/SimpleList.mrt");
report.renderAsync(function() {
	report.exportDocumentAsync(function (data) {
		Stimulsoft.System.StiObject.saveAs(data, "Report.pdf", "application/pdf");
	}, Stimulsoft.Report.StiExportFormat.Pdf);
});

This code is still fully functional, but you can do the same steps much easier with PHP code:
<?php
	$report = new \Stimulsoft\Report\StiReport();
	$report->loadFile('reports/SimpleList.mrt');
	$report->render();
	$report->exportDocument(\Stimulsoft\StiExportFormat::Pdf);
	$report->renderHtml();
?>

Even more features

Very soon, we will update the user manual, where you can read more about the functionality discussed above. For Reports.PHP and Dashboards.PHP products, we have updated all product samples, and you may find them available on GitHub. We are currently preparing the new videos that will be available on our YouTube channel.
By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.