koolphp / koolreport

This is an Open Source PHP Reporting Framework which you can use to write perfect data reports or to construct awesome dashboards using PHP
https://www.koolreport.com/
MIT License
226 stars 66 forks source link

How to insert parameters to KoolReport? #1

Open koolphp opened 6 years ago

koolphp commented 6 years ago

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.