Hi Tee,
Thanks for using KoolReport. KoolReport can be integrated into any MVC framework and CodeIgniter is one of them.
Below are basic steps to integrate KoolReport into CodeIgniter:
- Copy the koolreport folder into codeigniter/application/libraries folder.
- Create application/reports folder where you report will be stored.
- Create folder assets in the same level with folder application. Or if you have public assets folder where css and js file is hold then there is no need. But assume that you have
assets
folder that I suggested to create.
- In above folder, create two files
MyReport.php
and MyReport.view.php
. You may view the file below.
- In the application/controllers/Welcome.php, you do:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH."/reports/MyReport.php";
class Welcome extends CI_Controller {
public function index()
{
$report = new MyReport;
$report->run()->render();
}
}
<?php
//MyReport.php
require APPPATH."/libraries/koolreport/autoload.php";
class MyReport extends \koolreport\KoolReport
{
use \koolreport\clients\Bootstrap;
function settings()
{
return array(
"assets"=>array(
"path"=>"../../assets",
"url"=>"assets",
),
"dataSources"=>array(
"automaker"=>array(
"connectionString"=>"mysql:host=localhost;dbname=automaker",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
)
)
);
}
function setup()
{
$this->src('automaker')
->query("Select * from offices")
->pipe($this->dataStore("offices"));
}
}
<?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("offices"),
"class"=>array(
"table"=>"table table-hover"
)
));
?>
</body>
</html>
All done! The KoolReport has been successfully in CodeIgniter project. Couple of explanation regarding to assets
folders:
Since the KoolReport contains css/js needed to be accessed. If the koolreport folder is inside application folder of codeigniter, there is no way that those css/js can be accessed due to the rule of CI. That's why we have the assets
settings in the settings()
function of MyReport:
"assets"=>array(
"path"=>"../../assets",
"url"=>"assets",
),
This will direct KoolReport to copy all css/js to the assets folder so that they can access to. The path
is the relative path from MyReport.php
to the public assets folder. And the url
is the link to the assets folder in browser. In this case, assets folder is in the same folder with index.php
so we can simplly set "assets"
Some images;
Let us know if you need any further assistance.