Passing Criteria to Report

The relayCriteria() method behaves like the relay() method but allows passing of external values to the predefined Reportico criteria items. For example, you may wish to provide a user criteria item provided from within your web application (which may be picked up from the $_REQUEST array) and pass that through as a criteria filter to the Reportico query. The crtieria key passed through must equate to the name of a criteria item in the report.

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.

To pass a set of multiple selection values to a criteria just pass the values delimited by a comma.

To pass a date range pass in the format startdate-enddate in yyyy-mm-dd format, for example, yyyy-mm-dd-yyyy-mm-dd.



<?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. The key of country relates to the criteria name defined in the criteria() method.

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 ( {country} ) ]
                ORDER BY Country, LastName
                "
)

          ->
criteria("country")
            ->
title("Country")
            ->
type("lookup")
            ->
sql("SELECT DISTINCT Country country FROM northwind_employees")
            ->
widget("multi")
            ->
return("country")
            ->
display("country""country")
            ->
match("country")

          
// Passes a hardcoded value to the report sql. Note the 'country' in the relay key must match the
          // criteria name passed in the criteria method.
          
->relayCriteria("country""UK,USA")
          ->
execute();
?>