KoolReport's Forum

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

How to use KoolReport in Codeigniter? #31

Closed tee opened this topic on on Jul 18, 2017 - 39 comments

tee commented on Jul 18, 2017

Hi all,

Anyone knows how to integrate KoolReport into Codeigniter? I had followed the guideline by unzipped the folder and pasted into my project folder and created that three files (SalesByCustomer.php, SalesByCustomer.view.php and index.php). But it didn't work. Kindly tell me the steps clearly. Appreciated.

KoolReport commented on Jul 18, 2017

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:

  1. Copy the koolreport folder into codeigniter/application/libraries folder.
  2. Create application/reports folder where you report will be stored.
  3. 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.
  4. In above folder, create two files MyReport.php and MyReport.view.php. You may view the file below.
  5. 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.

tee commented on Jul 18, 2017

Images:

Still encountered error as shown above. Where should the examples folder be placed? Want to try using the sample databases provided.

KoolReport commented on Jul 18, 2017

It is because you have not had the automaker database. If you have downloaded the KoolReport's examples, you can find the automaker.sql.zip file in database folder. Import it into MySQL. Another solution, you can use your own database, put the connection into connectionString in settings() function.

tee commented on Jul 18, 2017

Hi KoolPHP Inc,

I did it!

KoolReport commented on Jul 18, 2017

Awesome :)

tee commented on Jul 19, 2017

I want to get user input by assigning $this->input->post('supplier') into variable of $supplier from image 1, how could i pass that variable to function setup() from image 2 so that the query will read only variable $supplier? Appreciated. Image 1:

Image 2:

KoolReport commented on Jul 19, 2017

You do this:

...
$report = new MyReport(array(
    "supplier"=>$supplier
));
$report->run()->render();
//MyReport.php
...
function setup()
{
    $this->src('automaker')
    ->query("select * from attendance where suppliers = @supplier")
    ->params(array(
        "@supplier"=>$this->params["supplier"]
    ))
    ->pipe($this->dataStore("att"));
}
tee commented on Jul 19, 2017

Hi KoolPHP Inc,

Why my output of table has no line and looked like so messy as shown in image 1 since i had followed your code provided as shown in image 2? Appreciated.

Image 1:

Image 2:

KoolReport commented on Jul 19, 2017

Basically the page is lack of jQuery and Bootstrap. As I explained about the assets folder already in my first answer, please follow the guideline.

tee commented on Jul 20, 2017

Thank you so much.

tee commented on Jul 20, 2017

Thank you so much.

tee commented on Jul 20, 2017

Hi KoolPHP Inc,

I have tried several times by not creating a new assets folder since my project already have assets folder which holds css and js. Why my displayed table still so messy? Appreciated.

KoolReport commented on Jul 20, 2017

Where is your assets folder located?

tee commented on Jul 20, 2017

Located at same level with application folder as shown below.

KoolReport commented on Jul 20, 2017

Then in your MyReport settings() function you do:

function settings()
{
    return array(
            "assets"=>array(
                "path"=>"../../assets", //Relative path the assets folder
                "url"=>"http://localhost/testing/assets", //Full url to assets folder from browser
            ),
    );
}

Make sure you have the use \koolreport\clients\Bootstrap; in the MyReport.php

Let me know if it works.

tee commented on Jul 20, 2017

Yes, it works. Thanks. KoolReport is amazing.

KoolReport commented on Jul 20, 2017

Sure, anything please let me know!

tee commented on Jul 21, 2017

Hi KoolPHP Inc,

When i tried to print out KoolReport as below, why some of the chart was disappeared?

KoolReport commented on Jul 21, 2017

Hi,

You mean when you hit the print the web page, one of the charts disappeared?

tee commented on Jul 22, 2017

Yes, you are right.

KoolReport commented on Jul 22, 2017

This could be issue with browser and nothing to do with the charts. The chart comes from Google as well so it should be able to print. Anything on the screen should be able to print out. One thing you can do is to play with the layouts of webpage. You can use our example layouts to see how since our examples do not have problem with printing.

Marty commented on Jul 24, 2017

Good guide! Thank you!

Jhon Errol Borlagdan commented on Mar 2, 2018

Hello there, i was following along with the steps that you provided and i encountered this error, can you help me please? I was using the latest version of codeigniter by the way.

KoolReport commented on Mar 2, 2018

Hi Jhon Errol Borlagdan,

Could you please let us know what version of PHP are you using?

Jhon Errol Borlagdan commented on Mar 2, 2018

Hi thanks for the response, i am using version 5.4.31.

KoolReport commented on Mar 2, 2018

That's bad. I've checked PHP documentation, it seems we have used a feature of later PHP 5.6. Please help us to do this. You open the koolreport/core/Widget.php, search for following and replace:

  1. DataStore::class and replace it with 'koolreport\core\DataStore'.
  2. Process::class to 'koolreport\core\Process'
  3. DataSource::class to 'koolreport\core\DataSource'
Jhon Errol Borlagdan commented on Mar 2, 2018

Tried searching and changing the codes from the code/Widget.php but resulted with another error, by the way i was using PHP 5.6.20.0 now and everything is working fine now, thanks for the response.

KoolReport commented on Mar 3, 2018

That's great!

Desi commented on Jul 12, 2018

I'm really a beginner, I have a codeigniter project and want to use koolreport to create a report, is there someone who can help me to use this koolreport in my CI project? Please help me, thank you

KoolReport commented on Jul 12, 2018

You may just follow our instruction in the first post to integrate KoolReport into CodeIgniter. Please download the CodeIgniter package as well.

Desi commented on Jul 13, 2018

Thank you KoolPHP Inc

Desi commented on Jul 13, 2018

do I have to create a controller for every report that I make? may i put them together in 1 controller file?

Thank u

Desi commented on Jul 13, 2018

I get error when I make the 3 files to that branch directory, and I had change the require APPATH in the controller... Someone help me how to fix it please...

KoolReport commented on Jul 13, 2018

In KoolReport, for the purpose of clarity, one class report going with one view: BranchReport.php is going with BranchReport.view.php. If you want to create another report, just create OtherReport.php with OtherReport.view.php.

For the controller of CodeIgniter, you can have only 1 controller that holds many actions, each action return a specific report.

class Reports extends CI_Controller()
{
    function branch_report()
    {
        $report = new BranhReport;
        $report->run()->render();
    }
    function other_report()
    {
        $report = new OtherReport;
        $report->run()->render();
    }
}

Hope that helps.

Desi commented on Jul 13, 2018

Its help me ,thank you

Desi commented on Jul 13, 2018

I am sorry I want to ask again So how about the require APPATH in the controller? Do I have to make like this?

require APPATH ."/reports/Branch Report.php"; require APPATH ."/reports/OtherReport.php";

and so on like that if i want to make a lot of reports??

Thank u

KoolReport commented on Jul 13, 2018

Yes, you have to, there seems no other ways.

navneet commented on Sep 24, 2018

Hi

I have done all you mentioned above. I might sound very beginner (I am :)). I don't know how to access it now. I mean the default page or url etc. in existing codeigniter project

Navneet

KoolReport commented on Sep 25, 2018

if you are using CodeIgniter, check out our CodeIgniter package. the flow is simple that you create your report class and view. Then in the controller of CodeIgniter, you create report object and render report in the view file of codeigniter. If you have not known how to access the page created by CodeIgniter, please take time and learn abit more of codeigniter, it is pretty easy.

P.S: Please check out repo koolreport/codeigniter4-example to see how koolreport is integrated inside CodeIgniter.

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
wiki
help needed

None