KoolReport's Forum

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

Upgrade from codeigniter 3.1.11 to 4.0.4 #1665

Closed Ron opened this topic on on Oct 14, 2020 - 13 comments

R
Ron commented on Oct 14, 2020

Hi,

I have an app working with koolreport and codeigniter 3.1.11. I started to upgrade to codeigniter 4.0.4 and also upgraded to the latest koolreport pro version. When I run the report on the new version of codeigniter I get an error. the error I get is on the line:

$report = new ReportName();

I did not change anything in the code. the same code is working on vesrion 3.1.11.

Can you please assist

K
KoolReport commented on Oct 14, 2020

May I know what error do you get?

R
Ron commented on Oct 14, 2020

There is an issue with codeigniter 4.0.4 errors and it does not show the right error in place but when I comment this line the error does not occur. anyway this is what I get in the error

R
Ron commented on Oct 14, 2020

it seems that codeigniter 4.0.4 is not showing the right error. maybe a bug in this version

R
Ron commented on Oct 14, 2020

I founded this in the codeigniter log file. maybe this can help

CRITICAL - 2020-10-14 11:54:12 --> Class 'App\Controllers\Teacher_schedule' not found #0 /var/www/osefer.com/public_html/dev/system/CodeIgniter.php(918): App\Controllers\Report->index() #1 /var/www/osefer.com/public_html/dev/system/CodeIgniter.php(404): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Report)) #2 /var/www/osefer.com/public_html/dev/system/CodeIgniter.php(312): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false) #3 /var/www/osefer.com/public_html/dev/public/index.php(45): CodeIgniter\CodeIgniter->run() #4 {main} CRITICAL - 2020-10-14 11:54:12 --> Uncaught ErrorException: print_r(): Couldn't fetch mysqli_result in /var/www/osefer.com/public_html/dev/app/Views/errors/html/error_exception.php:100 Stack trace: #0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'print_r(): Coul...', '/var/www/osefer...', 100, Array) #1 /var/www/osefer.com/public_html/dev/app/Views/errors/html/error_exception.php(100): print_r(Object(App\Controllers\Report), true) #2 /var/www/osefer.com/public_html/dev/system/Debug/Exceptions.php(308): include('/var/www/osefer...') #3 /var/www/osefer.com/public_html/dev/system/Debug/Exceptions.php(174): CodeIgniter\Debug\Exceptions->render(Object(Error), 500) #4 [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(Error)) #5 {main} thrown

R
Ron commented on Oct 14, 2020

this is the controller code to run the report:

<?php namespace App\Controllers;

//if ( isset( $_POST['output_report'] ) ){
//	require APPPATH."reports/".$_POST['output_report'].'.php';
//}
require APPPATH."Reports/Teacher_schedule.php";

class Report extends BaseController
{
	var $attributes;

	public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);
        // Creating new configuration object by hand
        $this->config = new \Config\Tts();
        $this->attributes =  $this->config->report;
    }

	public function index()
	{
		if ( $this->request->getPost('output_report') != null ) {
			switch ($this->request->getPost('output_report')) {
				case 'Substitute_teachers_monthly':
					if ( $this->request->getPost('substitute_month') != null ) {
						$report = new Substitute_teachers_monthly(array(
				    		"year" => 5780, //$this->getSchoolYear(),
							"date" => $this->request->getPost('substitute_month')
						));
						$report->run()->render();
					}
					break;

				case 'Teacher_schedule':
					if ( $this->request->getPost('teacher_id') != null ) {
						try
						{
							$report = new App\reports\Teacher_schedule(array(
								'year' => 5780,//$this->getSchoolYear(),
								'teacher_id' => $this->request->getPost('teacher_id'),
								'teachers_list' => $this->model->getTeachers($this->request->getPost('teacher_id'), true),
								'show_class' => $this->request->getPost('show_class'),
								'show_profession' => $this->request->getPost('show_profession'),
								'show_room' => $this->request->getPost('show_room')
							));
							$report->run()->render();
						}
						catch (\Exception $e)
						{
							var_dump($e->getMessage());
						}
					}
					break;
			}
		} else {
	        $this->attributes += array( 'teachers_list' => $this->model->getTeachers($this->request->getPost('teacher_id')) );
			//$report->run()->exportToExcel()->toBrowser("myreport.xlsx");
			//$this->gs();
			//Generate the view page
			echo view('templates/header', $this->attributes);
			echo view('report', $this->attributes );
			echo view('templates/footer', $this->attributes);
		}
	}
}
R
Ron commented on Oct 14, 2020

the problem occurs in the following line

$report = new App\reports\Teacher_schedule(array(
								'year' => 5780,//$this->getSchoolYear(),
								'teacher_id' => $this->request->getPost('teacher_id'),
								'teachers_list' => $this->model->getTeachers($this->request->getPost('teacher_id'), true),
								'show_class' => $this->request->getPost('show_class'),
								'show_profession' => $this->request->getPost('show_profession'),
								'show_room' => $this->request->getPost('show_room')
							));
K
KoolReport commented on Oct 14, 2020

The core issue is this error: Class 'App\Controllers\Teacher_schedule' not found. It seems to me the file Teacher_schedule.php is not included. The problem could be due to wrong path. Please check if the file is included. The insensitive case may cause this as I see some place you are using "Reports" and some place you are using "reports" to point to the namespace and the path to Teacher_schedule.

R
Ron commented on Oct 14, 2020

I generated a simple MyReport empt class as follows

<?php
//MyReport.php
require_once APPPATH."Libraries/koolreport/core/autoload.php";
class MyReport extends \koolreport\KoolReport
{
    function settings()
    {
    }

    function setup()
    {
    }
}

I call the following method from the controller

<?php namespace App\Controllers;

require APPPATH."Reports/MyReport.php";

class Report extends BaseController
{
	var $attributes;

	public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);
        // Creating new configuration object by hand
        $this->config = new \Config\Tts();
        $this->attributes =  $this->config->report;
    }

	public function index()
	{
		$report = new MyReport;
		$report->run()->render();
	}
}

The report is located in Reports folder (with capital R). I checked if it the right path on the server and it shows a correct path /var/www/osefer.com/public_html/dev/app/Reports/MyReport.php Still I have the same error: CRITICAL - 2020-10-14 13:34:32 --> Class 'App\Controllers\MyReport' not found

why it is looking the class in App\Controllers\MyReport. I already included in using the require command:

require APPPATH."Reports/MyReport.php";
R
Ron commented on Oct 14, 2020

ok I managed to solve part of the problem

$report = new \MyReport();

I just need to add a slash before the name of the report.

but now I have the following error:

Out of memory (allocated 102760448) (tried to allocate 98570240 bytes)

although I already set the following

ini_set('memory_limit', '-1');
R
Ron commented on Oct 14, 2020

ok. I managed to run the report. I have an issue with the assets folder in my code it shows

"assets"=>array(
     "path"=>"../../assets",
      "url"=>"assets",
),

I have to comment this lines for the report to run otherwise it give an error that assets folder can not be found. do I need to give the assets folder a special write permission chmod 777 -R ?

R
Ron commented on Oct 14, 2020

ok. also managed to fix the problem. you have to put the assets folder in the public folder in codeigniter 4.0.4

as follows:

"assets"=>array(
    "path"=>"../public/assets",
    "url"=>"assets",
),
K
KoolReport commented on Oct 15, 2020

That's awesome. Great to see that you have made it work. Your experience post will definitely help others as well. Thumb up!

R
Ron commented on Oct 15, 2020

Happy to help the KoolReport community

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
solved

CodeIgniter