Passing Values to Report

The relay() method allows values external to Reportico to be passed in for use in the report. For example, you may wish to pass a string for use in the report query which may have been provided from your web application (which may be picked up from the $_REQUEST array).

You can pass either an array of parameters to the method or pass key and value pairs as strings in a number of relay calls.

The key value passed must equate to the name of a criteria item created in the query. If you are passing multiple criteria filter values then the values can be separated by commas.

To use the parameters in the report to pass to a criteria element, use the notation
{USER_PARAM,relay_parameter_key}
For example :-
SELECT x, y
FROM table
WHERE column = "{USER_PARAM,my_parameter}"




<?php
      \Reportico\Engine\Builder
::build()
          ...
          ->
relay([array of parameters expressed as key value pairs])
          ->
relay(key_string,value_string)
          ...
          ->
execute();
?>
1


The following example runs the stock report, passing in the USA and Japan as report filter options. Note that we pass through the options with quotes in this example because the values are used within an SQL IN clause.

Run Demo


<?php

     
require_once(__DIR__ .'/../vendor/autoload.php');
      

     
\Reportico\Engine\Builder::build()
          ->
properties([ "bootstrap_preloaded" => true])
          ->
datasource()->database("mysql:host=localhost; dbname=DATABASE NAME")->user("USER")->password("PASSWORD")
          ->
title     ("Employee List")
          ->
description     ("Produces a list of our employees")

          ->
sql       ("
                SELECT EmployeeID employee_id, LastName last_name, FirstName first_name, date(BirthDate) birth_date, Country, BirthDate
                FROM northwind_employees
                WHERE 1 = 1
                [ AND Country IN ( {USER_PARAM,country} ) ]
                ORDER BY Country, LastName
                "
)

          
// Passes a hardcoded value to the report sql. Note the 'country' in the relay key must match the
          // USER_PARAM parameter above
          // the value passed could easily be a dynamic value 
          // passed from a form into the $_REQUEST php array.
          
->relay("country""'UK','USA'")
          ->
execute();
?>