Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
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.
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');
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.
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.
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.
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");
}
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"));
}
}
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>
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!
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!
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo