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 use KoolReport in Yii framework? #3

Open koolphp opened 6 years ago

koolphp commented 6 years ago

KoolReport can work with any PHP Framework in the market: CodeIgniter, Laravel, CakePHP, etc. You name it we have example for it. We design KoolReport to be flexible and can be a part of bigger system. We want KoolReport to do one thing and do it well. That is to provide great report/dashboard.

Yii is one of our favorite frameworks beside Laravel and CodeIgniter. We use Yii to code many project including this website. So today I would like to give some basic guide to integrate KoolReport into Yii Framework.

Steps:

  1. Download KoolReport and unzip
  2. Create extension folder in Yii protected folder to hold the library
  3. Copy the koolreport folder into extension folder
  4. Create folder reports to store your report.
  5. Create two files MyReport.php and MyReport.view.php in reports folder In MyReport, you need to required koolreport library like this require_once dirname(FILE)."/../extension/koolreport/autoload.php". The rest of setup report is the same.
  6. In any Yii controller that you want to use MyReport, you do require_once dirname(FILE)."/../reports/MyReport.php"
  7. In controller action, you can create MyReport as easy as $report = new MyReport; Now your report can be run and rendered. If you want you can run and render your report inside controller action. If not, you can pass the $report variable to the view of Yii. I recommend this way since we can utilize the layouts features of Yii framework.

To pass report variable to view, you do:

$this->render('myview',array(
    "report"=>$report,
));

To run and render report in the view (myview.php), you do:

...
<?php $report->run()->render(); ?>
...

Hope that helps.