KoolReport's Forum

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

KoolReport integrated with Codeigniter as MVC #129

Open Rohit opened this topic on on Oct 10, 2017 - 21 comments

Rohit commented on Oct 10, 2017

Dear sir, We have tried koolreport integration with CodeIgniter as mentioned in Forum's issue #31 but we want to keep MyReport.php files in Controllers and MyReport.view.php files in Views Please provide some detailed instructions on this topic.

KoolReport commented on Oct 10, 2017

Hi Rohit,

Basically you can put MyReport.php and MyReport.view.php in different folder and use the relative path from the MyReport.php to the MyReport.view.php. In the initiation, you do:

$report = new MyReport;
$report->run()->render("../views/MyReport");

Hope that helps.

Rohit commented on Oct 10, 2017

It is working fine. But I have a problem. I have made a header and a footer. I want to view my reports in between them. I tried it but the header came at the bottom. `

    this->load->view('Common/AgentHTMLHead');
    $agent->run()->render("../views/Ticket");
    $this->load->view('Common/AgentHTMLFooter');

KoolReport commented on Oct 11, 2017

It is understandable as the render() function will echo content right away while the load()->view() function of CodeIgniter do not render immediately. You may create an codeigniter view then inside the view you do:

$agent->run()->render("../views/Ticket");

Or you may pass the rendered content of KoolReport as string to a view, to get the rendered content as string, you do:

$content = $agent->run()->render("../views/Ticket",true);

After that you can pass the $content as parameter to any view to display.

Rohit commented on Oct 11, 2017

$agent->run()->render("../views/Ticket"); This worked properly. But when I tried the next one, I got only a single double quote i.e. " , in the $content.

KoolReport commented on Oct 11, 2017
$content  =  $agent->run()->render("../views/Ticket",true);
echo $content;

Do you mean after echoing, you only get single quotes.

I've tested over here and it seems working fine.

Rohit commented on Oct 13, 2017

I tried excel package normal way(without MVC) in that case it exports excel as the reports get rendered depending on the default binded parameters but i want to export my reports after taking inputs. i have made a button on click the report should be exported depending on the inputs.

But when i tried same thing in Codeigniter, reports did not even get exported while rendering it caused this error. Message: Call to undefined method Sla::exportToExcel()

Can u guide me on How to use excel package to export excel on click in Codeigniter.

KoolReport commented on Oct 15, 2017

So in your report file, you have use use \kooreport\excel\ExcelExportable; do you?

One thing you have to make sure that there is no output (even a single character) to browser before the exportToExcel()->toBrowser() is called. Otherwise the result will be tampered and caused file corruption.

Rohit commented on Oct 16, 2017

I have Load button for custom daterange and i have added one export button beside Load button which calls my second function(sla1) First function(sla) only renders the file and displays it and in Second function(sla1) it 1st calls ExportToExcel and then renders so it downloads my excel report but problem is it contains data associated with default dateRange not with custom range

public function sla()
    {
        require APPPATH."/reports/Sla.php";
        $sla = new Sla;
        $sla->run()->render("../views/Sla");
    }

    public function sla1()
    {
        require APPPATH."/reports/Sla.php";
        $sla = new Sla;
        $sla->run()->exportToExcel(array(
            "dataStores" => array(
                'response',
                'resolution')
        ))->toBrowser("exp1.xlsx")->render("../views/Sla");
    }
David Winterburn commented on Oct 16, 2017

Hi Rohit,

Would you please post your Sla.php code? Thanks!

Rohit commented on Oct 16, 2017

Code in my previous comment is of Controllers function from Codeigniter

Sla.php

<?php

require_once APPPATH."/libraries/koolreport/autoload.php";
use \koolreport\KoolReport;

class Sla extends KoolReport
{
    use \koolreport\clients\Bootstrap;
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    use \koolreport\excel\ExcelExportable;

protected function defaultParamValues()
    {
        return array(
	       "dateRange"=>array(
            "2017-01-01",
            "2017-09-31"
            ),
       );
    }

protected function bindParamsToInputs()
    {
        return array(
           "dateRange"=>"dateRange",
        );
    }

public function settings()
    {
        return array(
           "dataSources"=>array(
                "DB"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=db",
                    "username"=>"root",
                    "password"=>"password",
                    "charset"=>"utf8",
                )
        ));
    }


protected function setup()
    {	

	$this->src("DB")

        ->query("some query")
           	
    	->params(array(
    	    ":start"=>$this->params["dateRange"][0],
            ":end1"=>$this->params["dateRange"][1],
            ))
    ->pipe($this->dataStore("response"));


    }
}
 


David Winterburn commented on Oct 16, 2017

Hi Rohit,

Thanks for your feedback! I forgot this but would you also please post the php code of the view page and/or index page which include the Export button? Thanks!

Rohit commented on Oct 16, 2017

index.php is same as my sla function from controller of codeigniter

Sla.view.php

<?php

use \koolreport\inputs\DateRangePicker;
use \koolreport\widgets\koolphp\Table;
use \koolreport\clients\Bootstrap;


?>


<html>
    <head>
        <title>SLA Report</title>
    </head>
    <body>

<link rel="stylesheet" type="text/css" href="assets/css/felicity_styles.css">

        <div class="col-md-12 report-form-con">

                <h1>SLA Report</h1>

            <form method="post">


                    <div class= "row">

                        <div class="col-md-6 col-md-offset-3 form-group">
                            <label>Select DateRange of Ticket Creation</label>
                            <?php 
                                DateRangePicker::create(array(
                                    "name"=>"dateRange",
                                    "attributes"=>array(
                                        "class"=>"form-control",
                                    )
                                ));
                                ?>
                        </div>
                    </div>   

        </div>
    
        <div class="form-group text-center">
            <button class="btn btn-success"><i class="glyphicon glyphicon-refresh"></i> Load</button>

            <a href="Slaexport" class=" btn btn-info glyphicon glyphicon-export">Export</a>
        </div>


        
        <?php
        if($this->dataStore("response")->countData() && $this->dataStore("resolution")->countData() >0)
            {

        ?>
            <div class="text-center">
                <h1>SLA Response Report</h1>
            </div>
        <div class="col-md-12">
        <?php 
            Table::create(array(
                "dataStore"=>$this->dataStore("response"),
                "columns"=>array(
                    "ticket_number"=>array(
                    "label"=>"Ticket No",
                    "type"=>"string"
                    ),
                    "subject"=>array(
                    "type"=>"string",
                    "label"=>"Title"
                    ),
                    
                ),
                "paging"=>array(
                    "pageSize"=>10,
                    "align"=>"center",
                    "pageIndex"=>0,
                ),
                "cssClass"=>array(
                    "table"=>"table table-hover table-bordered"
                )
            ));
        ?>
        </div>
        
        

        else
        {
        ?>
                <div class="alert alert-warning">
                    <i class="glyphicon glyphicon-info-sign"></i> Sorry, we have not found any data..!!!
                </div>
        <?php
        }
        ?>
        
        
</form>
       
    

    </body>
</html>

Rohit commented on Oct 18, 2017

Hey KoolReport, any updates

David Winterburn commented on Oct 18, 2017

Hi Rohit,

Thanks for your feedback! The problem with export data not persistent with input the input filters is because when we change to the export page, all the input filters are lost.

To solve this problem, I suggest you change the export button from < a href...> to a submit button. You could put another < form id="exportForm" action="Slaexport.php"> around the input controls' form and when clicking the export button you find the exportForm to submit it. Using this way the export page could retrieve the input filters.

Please try this and let us know if it works for you. Thanks!

David Winterburn commented on Oct 19, 2017

Hi Rohit,

To clarify the previous post, it's better to use only one form for both the input controls and the download button. But in the download button please set the formaction like this:

 <button formaction="Slaexport.php">Download</button>

This should work with all html5 supported browsers. Thanks!

Rohit commented on Oct 31, 2017

My reports are getting exported with filtered data selected from input controls but even using same code for all of my reports some are getting exported perfectly and opens in excel but some are causing issues like

please help

Rohit commented on Nov 1, 2017

I changed type to Excel2007 and it worked

KoolReport commented on Nov 1, 2017

Oh great :) thanks for the update. Have you been able to download the newest version and inputs package as well and keep only 1 copy of library as I emailed you?

Rohit commented on Nov 1, 2017

yeah i did that and it is also working fine

KoolReport commented on Nov 1, 2017

Awesome

infra commented on Mar 13, 2019

we are try to create PDF report in Code-igniterm we need sample report

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

None