Setting Report Variables on the Server-Side
Our sample projects and report templates can help you learn the basics of working with our products.Report variables can be assigned on the server before rendering — the
Set variable values in PHP.
How it works. Values chosen on the server are injected into the report generator, so the client renders with data it never had to supply.
onPrepareVariables event supplies values that flow into the report generator.Set variable values in PHP.
$viewer = new StiViewer();
$viewer->javascript->relativePath = '../';
$viewer->onPrepareVariables = function (StiVariablesEventArgs $args) {
if (count($args->variables) > 0) {
$args->variables['Name']->value = 'Maria';
$args->variables['Surname']->value = 'Anders';
$args->variables['BirthDay']->value = '1982-03-20 00:00:00';
}
};
$viewer->process();
$report->loadFile('../reports/Variables.mrt');
$viewer->report = $report;onPrepareVariables— server event that receives the report's variables before rendering.$args->variables['Name']->value— assign each value by name; types must match those defined in the template.
How it works. Values chosen on the server are injected into the report generator, so the client renders with data it never had to supply.