KoolReport's Forum

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

How to create PDF/Excel Report in KoolReports in CodeIgniter environment #740

Closed infra opened this topic on on Mar 13, 2019 - 2 comments

infra commented on Mar 13, 2019

Dear Support

We are creating Family Head Report in Codeigniter using KoolReport, Report has been created successfully but when we converting report in PDF we having following Errors "Object not found!"

Our Reports are under: D:\xampp\htdocs\dba\application\reports\census 1. FamilyHead.php 2. FamilyHead.view.php 3. FamilyHeadPdf.view.php 4. export.php

but when press PDF button on Report its show path like this "http://localhost/dba/export.php" its surprising for us why its find export.php at this path its should be looking for " D:\xampp\htdocs\dba\application\reports\census"

Kindly help us or make it one sample report under CodeIgniter enviroment with kool report to make PDF report

// Main Report FamilyHead // FamilyHead.php <?php

require APPPATH."/libraries/koolreport/autoload.php";

use \koolreport\KoolReport;

class FamilyHead extends \koolreport\KoolReport {

 use \koolreport\codeigniter\Friendship;
use \koolreport\clients\Bootstrap;
use \koolreport\export\Exportable;
function settings()
{
    //Get default connection from config.php
           
    $config = include "config.php";

    return array(
        "dataSources"=>array(
            "cences_db"=>$config["cences_db"]
        )
    );

    return array(
        "assets"=>array(
            "path"=>"/../../../assets",
            "url"=>"assets",
        ));
   }   
protected function setup()
{
    //$this->src('cences_db')
    $this->src('cences_db')
    ->query("SELECT HeadID,FirstName,Prov,CityDivision,MainArea,FormStatus 
                from headoffamily where id <20 ")
    ->pipe($this->dataStore("FamilyHead"));
} 

}

// VIEW //FamilyHead.view.php

<?php

use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\ColumnChart;

?> <html>

<head>
    <title>Student Information </title></title>
</head>
<body>
    <h1>FamilyHead</h1>
    <h3>List of Family Heads</h3>

     <p class="lead">This example show how to export report to PDF</p>
    <a href="export.php" class="btn btn-primary">Download PDF</a>

    
    <?php
    Table::create(array(
    //ColumnChart::create(array(
        "dataStore"=>$this->dataStore("FamilyHead"),
        "class"=>array(
                        //"table"=>"table table-hover"
                        "table"=>"table-bordered table-striped table-hover"
                       )
                    ));
    ?>

   </body>

</html>

//PDF Report // FamilyHeadPdf.view.php

<?php

use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\ColumnChart;

?> <html>

<body style="margin:0.5in 1in 0.5in 1in">
    <link rel="stylesheet" href="../../../assets/bs3/bootstrap.min.css" />
    <link rel="stylesheet" href="../../../assets/bs3/bootstrap-theme.min.css" />   
    <div class="page-header" style="text-align:right"><i>Family Report</i></div>
    <div class="page-footer" style="text-align:right">{pageNum}</div>
    <div class="text-center">
        <h1>Head of Family</h1>
        <h4>This report show the no of Family Heads</h4>
    </div>
    <hr/>

 
   <?php
    Table::create(array(
    //ColumnChart::create(array(
        "dataStore"=>$this->dataStore("FamilyHead"),
        "class"=>array(
                        //"table"=>"table table-hover"
                        "table"=>"table-bordered table-striped table-hover"
                       )
                    ));
    ?>
</body>

</html>

//export.php

<?php require_once "FamilyHead.php"; $report = new FamilyHead;

$report->run() ->export('FamilyHeadPdf') ->pdf(array(

"format"=>"A4",
"orientation"=>"portrait",
//"zoom"=>2

)) ->toBrowser("Family_Head.pdf");

KoolReport commented on Mar 14, 2019

The solution that I suggested to infra through email was:

  1. Make an action in controller to host the export function
  2. In the link tag of Export, put the href to above action in controller.
infra commented on Mar 14, 2019

Thanks Karl its great now its working

I would like to share what we after Karl guide line //Controller change we did as below mention for others

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH."reports/census/FamilyHead.php";

class census extends CI_Controller {

	public function index()
	{
		$report = new FamilyHead;
		$report->run()->render();
		//$report->run()->export()->pdf(array
		//	("format"=>"A4", "orientation"=>"portrait") )->toBrowser("FamilyHead.pdf");
						
		// $report = new PivotArttStudents;
		//$report = new PivotArttStudents(array("BatchID"=>64));
		
		//$this->load->view('welcome_message');
	}
            // this function we added , it was part of export file
	public function headpdf()
	{
	    $report = new FamilyHead;
		$report->run()
			->export('FamilyHeadPdf')
			->pdf(array(
    		"format"=>"A4",
    		"orientation"=>"portrait",
    	))
		->toBrowser("Family_Head.pdf");

	}
}

// Addd following code in view file "FamilyHead.view.php"

<a href="<?php echo base_url('census/headpdf'); ?>"class="btn btn-primary">Download PDF</a>

Regards Ali

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
solved

Export