Instant\Widget

Settings #

namereturndescription
create(string $widgetClassName, array $widgetParams)nullRender 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);
?>