在 Yii2 环境中轻松设置报告

1.0.0 2020-01-17 10:25 UTC

This package is auto-updated.

Last update: 2024-09-21 21:04:23 UTC


README

koolreport/yii2 包有助于在 Yii2 环境中轻松创建 KoolReport 报告。它可以自动配置 assets 路径和 URL。此外,它还提供与 Yii2 数据库连接配置的 default 数据源。

安装

通过下载 .zip 文件

  1. 下载
  2. 解压 zip 文件
  3. yii2 文件夹复制到 koolreport 文件夹中,使其看起来如下
koolreport
├── core
├── yii2

通过 composer

composer require koolreport/yii2

文档

步骤教程

第 1 步:创建报告并与 Laravel 建立友谊

  1. 首先,在根文件夹内创建 reports 文件夹
  2. 在 reports 文件夹内,创建两个文件 MyReport.phpMyReport.view.php
  3. 在报告中添加 use \koolreport\yii2\Friendship,如下所示

MyReport.php

<?php
namespace app\reports;

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\yii2\Friendship;
    // By adding above statement, you have claim the friendship between two frameworks
    // As a result, this report will be able to accessed all databases of Yii2
    // There are no need to define the settings() function anymore
    // while you can do so if you have other datasources rather than those
    // defined in Laravel.
    

    function setup()
    {
        $this->src("default")
        ->query("SELECT * FROM offices")
        ->pipe($this->dataStore("offices"));        
    }
}

MyReport.view.php

<?php
use \koolreport\widgets\koolphp\Table;
?>
<html>
    <head>
    <title>My Report</title>
    </head>
    <body>
        <h1>It works</h1>
        <?php
        Table::create([
            "dataSource"=>$this->dataStore("offices")
        ]);
        ?>
    </body>
</html>

第 2 步:运行报告并显示报告

现在已经有了 MyReport,为了在 Yii2 中显示报告,你需要在控制器中创建 MyReport 的对象,并将其传递给视图以进行渲染。

HomeController.php

<?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;

class SiteController extends Controller
{
    ...
    public function actionReport()
    {
        $report = new \app\reports\MyReport;
        $report->run();
        return $this->render('report',array(
            "report"=>$report
        ));
        
    }
}

report.php

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

支持

如果您需要支持,请使用我们的论坛,这样其他人也可以从中受益。如果支持请求需要隐私,您可以发送电子邮件至 support@koolreport.com