Registry Mirror
Skip to content

How to use KoolReport in Codeigniter? #4

Open

Description

@koolphp

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 image to illustrate:
image

image

image

Activity

  1. daN4cat commented on Apr 15, 2018

    @daN4cat

    Question, why do you need to copy koolreport to codeigniter/application/libraries?
    Isn't composer and vendor supported?

  2. koolphp commented on Apr 16, 2018

    @koolphp
    OwnerAuthor

    Yes, KoolReport support installing through composer, if you installed through composer you do not need to copy files or require the "autoload.php" of KoolReport

  3. koolphp commented on Jul 18, 2018

    @koolphp
    OwnerAuthor

    We have create CodeIgniter package to make KoolReport work seamlessly inside CodeIgniter. While KoolReport is working well with CodeIgniter from the beginning, however there are two issues that most people asked:

    1. How to make KoolReport use the databases settings from CodeIgniter?
    2. How to publish the KoolReport's widget resources files to public folder?

    So this new package will help you to do above things with a simple line of code:

    class MyReport extends \koolreport\KoolReport
    {
        use \koolreport\codeigniter\Friendship;// All you need to do is to claim this friendship
    
        function setup()
        {
            //Now you can access database that you configured in codeigniter
            $this->src("sale_database")
            ->query("select * from orders")
            ->pipe($this->dataStore("orders"));
        }
    }
    

    Simple, isn't it?

    The package is TOTALLY FREE so you can just download it. FYI, we also create the same package for Laravel as well. We plan to add more packages like this for other PHP Frameworks like Symfony, CakePHP, Yii2 etc.

    Hope that helps.

    Regards

  4. wvaquerano commented on May 12, 2020

    @wvaquerano

    Hi @koolphp I have installed using composer both KoolReport and CodeIgniter packages. I created the reports folder in the application and used friendship but CodeIgniter is not finding the kool report class.
    `<?php
    class MyReport extends \koolreport\KoolReport
    {
    use \koolreport\codeigniter\Friendship;// All you need to do is to claim this friendship
    //use \koolreport\clients\Bootstrap;

    function setup()
    {
        //Now you can access database that you configured in codeigniter
        $this->src("recursoshumanos")
        ->query("select * from licenciaporempleado")
        ->pipe($this->dataStore("licencias"));
    }
    

    }?>`
    image

  5. basirebadi commented on Feb 9, 2021

    @basirebadi

    Please replace the bellow path in MyReport.php file, it will work.

    require APPPATH."/libraries/koolreport/autoload.php"; (old)

    require APPPATH."libraries\koolreport\core\autoload.php"; (replace with this one).

    thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions