KoolReport and Symfony
Overview #
KoolReport works great with Symfony Framework like any other PHP MVC Framework.
Guide #
We have created Symfony-Example Repository to demonstrate our tutorial.
Install KoolReport #
Adding koolreport/core
into your composer.json
{
"requires"=>{
...
"koolreport/core":"*"
}
}
and run
composer update
Now KoolReport is available in your Symfony application.
Create your report #
- Under
src
folder, you create folderReports
to hold reports - Inside
Reports
folder, you createMyReport.php
andMyReport.view.php
, please view our code in above repository. - Make the
MyReport
class under namespaceApp\Reports
Render report #
Now in your controller's action, you can render report like this:
/**
* @Route("/site/report")
*/
public function report()
{
$report = new \App\Reports\MyReport;
return new Response($report->run()->render());
}
or if you want to render report inside twig template you can do:
/**
* @Route("/site/reportwithtemplate")
*/
public function template()
{
$report = new \App\Reports\MyReport;
return $this->render('report.html.twig', [
'myreport' =>$report->run()->render(true)
]);
}
and here is the content of your twig template:
<html>
<head>
<title>Render KoolReport inside Twig Template</title>
</head>
<body>
<h1>Render KoolReport inside Twig Template</h1>
{{myreport|raw}}
</body>
</html>
Now if you run
http://localhost:8000/site/report
or
http://localhost:8000/site/reportwithtemplate
you will see your report!
Summary #
In this tutorial, we have shown how to use KoolReport inside Symfony web application. You can render report directly or use wit twig template. Hope that this tutorial helps you to get started faster with KoolReport.
Happy reporting!
Get started with KoolReport
KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.