koolreport icon indicating copy to clipboard operation
koolreport copied to clipboard

How to insert parameters to KoolReport?

Open koolphp opened this issue 7 years ago • 0 comments

KoolReport is able to create dynamic report which received parameters from outside. Let say we want to create a SaleReport which summarize sales for each months of a given year.

We can do this:

<?php
$saleReport = new SaleReport(array(
    "year"=>2005
));
$saleReport->run()->render();

Here is our SaleReport.php setup:

<?php
class SaleReport extends from \koolreport\KoolReport
{
    ...
    function setup()
    {
        //In here you can get the year from $this->params["year']
        $year = $this->params["year"];
        $this->src("sales")->query("
            SELECT month,sum(sale)
            FROM tbl_sales
            WHERE year=$year
            GROUP BY month
        ")->pipe($this->dataStore('month-of-year'));
    }
}

The example show how KoolReport can get parameters and access it in setup() or setting() function.

koolphp avatar Sep 01 '17 08:09 koolphp