KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Using model codeigniter #365

Open epba opened this topic on on Jul 11, 2018 - 13 comments

epba commented on Jul 11, 2018

can i using data from resyult query model codeigniter ?

KoolReport commented on Jul 11, 2018

Not yet, but you can query directly to database of CI with simple line of settings code, please download new version of KoolReport (2.75.0) from here and get the CodeIgniter package. You can directly put query to database, if you want to use querybuilder, you can get QueryBuilder package. It is very convenient to use and those packages are free.

epba commented on Jul 11, 2018

waw , fast response thanks...

btw, can i using data array from controller ?

KoolReport commented on Jul 11, 2018

Do you mean array of data from CI controller? You want to send to KoolReport for processing and visualizing.

epba commented on Jul 11, 2018

yup , can i ?

KoolReport commented on Jul 11, 2018

Yes, sure, you do this:

In the controller, suppose you have an array of associate array name $myarray

$report = new MyReport(array(
    "myarray"=>$myarray
));
$report->run();

In the MyReport.php

class MyReport extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "myarray_source"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"associate",
                    "data"=>$this->params["myarray"]
                ),
            )
        );
    }

    function setup()
    {
        $this->src("myarray_source")
        ->pipe(...)
        ...
    }
}
epba commented on Jul 11, 2018

waw, thanks.... very helpful

KoolReport commented on Jul 11, 2018

You are welcome!

epba commented on Jul 11, 2018

hi , i have some error... data not showing. please help

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH."/reports/MyReport.php";

class Welcome extends CI_Controller {

	public function index()
	{
		$myarray = ["ketoprak","lengko","ayam"];
		$report  = new MyReport(array(
			"myarray"=>$myarray
		));
		$report->run();
	}
}

<?php
//MyReport.php
require APPPATH."/libraries/koolreport/autoload.php";

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\clients\Bootstrap; 
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "myarray_source"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>[$this->params["myarray"]
                ),
            )
        );
    }

    function setup()
    {
        $this->src("myarray_source")
        ->pipe(
            $this->dataStore("data")
        );
    }
}
<?php
    //MyReport.view.php
use \koolreport\widgets\koolphp\Table;
?>
<html>
<head>
    <title>MyReport</title></title>
</head>
<body>
    <h1>MyReport</h1>
    <h3>List all offices</h3>
    <?php
    Table::create(array(
        "dataStore"=>$this->dataStore("data"),
        "class"=>array(
            "table"=>"table table-hover"
        )
    ));
    ?>
</body>
</html>
KoolReport commented on Jul 11, 2018

Since you are using table dataFormat, you data should look like this:

$myarray = [
    ["age","weight"],
    [11,13],
    [5,7]
];

It is an two dimension array, let imagine like a rows of table with the first row is the name of columns.

epba commented on Jul 11, 2018

still not showing data, just blank page

KoolReport commented on Jul 11, 2018

Try this:

$report->run()->render();
epba commented on Jul 11, 2018

thanks, it works

MarkoS commented on Oct 13, 2020

Hi all, I am trying to make module with controllers and views by using this example: https://www.koolreport.com/forum/topics/31

I am having problem that my data does not load at all. Looks like that view isn't getting any data for dataStore

My controller:

<?php
require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php'); 
require MODULES_PATH."/reporting/libraries/MyReport.php";

class Dashboard extends Fuel_base_controller {

function __construct()
{
	parent::__construct();
	$this->load->config('reporting');
	$config = $this->config->item('reporting');
	$this->_validate_user($config['permission']);
	$this->load->vars($config);
}

function index()
{
	$report = new MyReport;
// $report->run()->render();
// $report->run();
	$this->load->view('reporting_dashboard');
}

}

View:

<?php
//reporting_dashboard.php  view
use \koolreport\widgets\koolphp\Table;

?>

    <h1>Report</h1>
    <h3>Detailed chart table</h3>
<?php

    $data = array(
    array("category"=>"Books","sale"=>32000,"cost"=>20000,"profit"=>12000),
    array("category"=>"Accessories","sale"=>43000,"cost"=>36000,"profit"=>7000),
    array("category"=>"Phones","sale"=>54000,"cost"=>39000,"profit"=>15000),
    array("category"=>"Movies","sale"=>23000,"cost"=>18000,"profit"=>5000),
    array("category"=>"Others","sale"=>12000,"cost"=>6000,"profit"=>6000)
    );
    
    Table::create(array(
        // "dataStore"=>$data,
        "dataStore"=>$this->dataStore("korisnici"),
        "class"=>array(
            "table"=>"table table-hover"
        )
    ));
?>

When local array $data is used, table is displayed properly. But dataStore not. I wand to load view by using __$this->load->view('reporting_dashboard'); __ if possible. I had to comment line //$report->run()->render(); because it does render data and show in some strange way with Heading on top " $this->dataStore('korisnici')"

Does anyone knows what could be wrong and how can I check is dataStore passed to view?

Update: I have discovered error pointing to dataStore

I do not know why and how to resolve this.

Thanks!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

CodeIgniter