koolreport/instant
Composer 安装命令:
composer require koolreport/instant
包简介
Allow rendering widget instantly
README 文档
README
Sometimes, we need to show some tables or charts in our page but setting up the whole KoolReport, despite of ease, causes trouble and is not convenient. The Instant package allows us to create report or widget instantly everywhere without setting up a full report.
Beside Instant package can help you to export any file whether it is html or php to PDF and other formats.
Installation
- Download and unzip the zipped file
- Copy
instantfolder intokoolreport\instantfolder
Documentation
Widget
| name | return | description |
|---|---|---|
| create(string $widgetClassName, array $widgetParams) | null | Render the widget. This static function requires $widgetClassName which is the name of widget you want to create and $widgetParams which is any parameters you want to pass to the widget |
Examples
Create KoolPHP Table
Below are example of how to create Table on your PHP page
<?php
require_once "koolreport\autoload.php";
use \koolreport\instant\Widget;
use \koolreport\widgets\koolphp\Table;
?>
<html>
<head>
<title>Instant Table</title>
</head>
<body>
<?php
Widget::create(Table::class,array(
"dataSource"=>array(
array("name"=>"Peter","age"=>35),
array("name"=>"Karl","age"=>32),
)
));
?>
</body>
</html>
As you see, you do not need to setup the whole KoolReport class and the view in order to use our Widget. With the Instance package, you can create any widgets you want.
Create Google BarChart
<?php
require_once "koolreport\autoload.php";
use \koolreport\instant\Widget;
use \koolreport\widgets\google\BarChart;
?>
<html>
<head>
<title>Instant Table</title>
</head>
<body>
<?php
Widget::create(BarChart::class,array(
"dataSource"=>array(
array("name"=>"Peter","age"=>35),
array("name"=>"Karl","age"=>32),
)
));
?>
</body>
</html>
Create PieChart
<?php
require_once "koolreport\autoload.php";
use \koolreport\instant\Widget;
use \koolreport\widgets\google\PieChart;
?>
<html>
<head>
<title>Instant Table</title>
</head>
<body>
<?php
Widget::create(PieChart::class,array(
"dataSource"=>array(
array("browser"=>"Chrome","usage"=>44.5),
array("browser"=>"Safari","usage"=>25.4),
array("browser"=>"Internet Explorer","usage"=>15.5),
array("browser"=>"Firefox","usage"=>7.4),
array("browser"=>"Others","usage"=>7.2),
)
));
?>
</body>
</html>
Assets Folder
Automatically create assets folder
By default, Instant package will create koolreport_assets folder automatically to hold the resources of widgets. This will assure that all widgets work seamlessly.
Manually create assets folder
If you want to organize all koolreport widget's resources into a pre-created assets folder of your own, you may do so. For example, you have assets folder created, you can do like below:
<?php
Widget::create(Table::class,array(
"dataSource"=>array(
array("name"=>"Peter","age"=>35),
array("name"=>"Karl","age"=>32),
)
),array(
"path"=>"../../assets"
"url"=>"/assets",
));
?>
The third parameter of create function is optional settings for assets folder. This assets settings is necessary if browser can not access to the folder containing resources of Widget. By specifying the path and url, we let KoolReport know where to put Widget's resources and how to access those resources.
Turn off this feature
If you put KoolReport library in folder that can be accessed by browser, there will not be need for create assets folder. So you may tell instant package not to create any assets folder. Just input false value into the third parameter like below
<?php
Widget::create(Table::class,array(
"dataSource"=>array(
array("name"=>"Peter","age"=>35),
array("name"=>"Karl","age"=>32),
)
),false);
?>
Exporter
Exporter helps you to ulilize the Export package (if you have) to export any HTML or PHP code file to PDF and other formats.
<?php
require_once "koolreport/autoload.php";
use \koolreport\instant\Exporter;
Exporter::export("/full/path/to/your/file.php")
->pdf(array(
"format"=>"A4",
"orientation"=>"portrait"
))
->toBrowser("myfile.pdf");
or you can save file
Exporter::export("/full/path/to/your/file.php")
->pdf(array(
"format"=>"A4",
"orientation"=>"portrait"
))
->saveAs("myfile.pdf");
SinglePage
As you may know, to start a report, we normally need 3 files: a controller class file(ex.MyReport.php), a view file (ex. MyReport.view.php) and a initiation file (index.php). The SinglePage allows us to create report in just one file, bundling all the controller, view and initiation file into one. Please view below example:
<?php
//Index.php
require_once "../../../koolreport/autoload.php";
use \koolreport\querybuilder\DB;
use \koolreport\widgets\koolphp\Table;
class MyReport extends \koolreport\KoolReport
{
use \koolreport\instant\SinglePage;
use \koolreport\clients\Bootstrap;
function settings()
{
return array(
"dataSources"=>array(
"automaker"=>array(
"connectionString"=>"mysql:host=localhost;dbname=automaker",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
),
),
);
}
function setup()
{
$this->src('automaker')->query(
DB::table("customers")->select("customerNumber","customerName")
)
->pipe($this->dataStore("mydata"));
}
}
$report = new MyReport;
$report->start();
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Testing</h1>
<?php
Table::create(array(
"dataSource"=>$report->dataStore('mydata')
));
?>
</body>
</html>
<?php $report->end(); ?>
As you may see from above example, we only have 1 file index.php containing controller classes MyReport and the view inside the start() and end() methods of report. We declare use \koolreport\instant\SinglePage; inside MyReport to provide two important methods above.
Support
Please use our forum if you need support, by this way other people can benefit as well. If the support request need privacy, you may send email to us at support@koolreport.com.
koolreport/instant 适用场景与选型建议
koolreport/instant 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 184.39k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「Data Report」 「Reporting Tools」 「Instant Report」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 koolreport/instant 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koolreport/instant 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 koolreport/instant 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Reportico Open Source PHP Report Designer
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
Allow KoolReport to use twig template engine to render view
Data provider for yii2
统计信息
- 总下载量: 184.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-09