Samples

 

You can find a full code of on the GitHub.

 

 

 

To use the product, you should download the ZIP archive of the product from the Downloads page of our site, unpack it, and copy the contents of the /PHP folder to your Web server. This folder is a Web project that contains all the necessary files and resources for the product and samples 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:

 

console

 

composer require stimulsoft/reports-php

 

 

 

When working with the product, in most cases, it is enough to use only PHP code, which ensures the operation of all the main features. For a more detailed configuration of the product and the use of all features, you must use JavaScript code. Next, two options for using certain features will be described - using PHP and JavaScript functions. Depending on your needs, you may use either the first or the second option.

 

To use the reporting tool in a Web project, you should add scripts to the <head> block on the PHP page. You can do this using the StiJavaScript PHP class. In the constructor, you need to specify the type of component to deploy:

 

index.php

 

<head>

<?php

$js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Report);

$js->renderHtml();

?>

</head>

 

 

 

Also, you may connect all the necessary scripts using the <script> block. All product scripts are located in the vendor/stimulsoft/reports-php/public/scripts/ directory:

 

index.php

 

<head>

<script src="vendor/stimulsoft/reports-php/scripts/stimulsoft.reports.js" type="text/javascript"></script>

</head>

 

 

 

For dashboards, you need to connect the following package:

 

console

 

composer require stimulsoft/dashboards-php

 

 

 

In the case of using PHP code, all necessary scripts will be enabled automatically. No code change is required. If you use JavaScript code, you will need to add the appropriate script file that contains everything you need to work with analytical panels:

 

index.php

 

<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>

</head>

 

 

 

Then, you can use PHP classes and functions to work with reports, which must be placed inside the <script> block. For example, you want to load a report from a file and render it:

 

index.php

 

<script type="text/javascript">

<?php

$report = new \Stimulsoft\Report\StiReport();

$report->loadFile('reports/SimpleList.mrt');

$report->render('onAfterRender');

$report->renderHtml();

?>

 

function onAfterRender() {

alert('Done!');

}

</script>

 

 

Information

 

Stimulsoft Reports.PHP and Stimulsoft Dashboards.PHP do not have a native PHP report engine; report rendering and export are performed on the client side using JavaScript code. Therefore, when using PHP code to work with components, it is necessary to call the renderHtml() function, which will add the appropriate JavaScript code to the Web page to perform all the required actions.

 

 

 

If necessary, the same actions can be performed using JavaScript functions:

 

index.php

 

<script type="text/javascript">

var report = new Stimulsoft.Report.StiReport();

report.loadFile("reports/SimpleList.mrt");

report.renderAsync(function() {

alert("Done!");

})

</script>

 

 

 

Managing the URL for loading JavaScript reporting tool files

By default, all product .js files are loaded via URLs relative to the location of the current PHP script. In some cases, this behavior needs to be changed. For this purpose, there are two options for the StiJavaScript class. To use an absolute path for loading all product scripts, you must set the useRelativeUrls option to true:

 

index.php

 

<?php

  $js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Report);

  $js->useRelativeUrls = true;

?>

 

 

 

To adjust the relative path, the relativePath option is provided, for which you need to set a string value that will be used when generating the script loading URL. In this case, the useRelativeUrls option must be disabled (the default value is used).

 

index.php

 

<?php

  $js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Report);

  $js->relativePath = '../../';

?>

 

 

 

Various alternatives of deployment and optimization are considered in the Optimization of script loading chapter.