CodeIgniter Forums
Class 'CI_Controller' not found - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Class 'CI_Controller' not found (/showthread.php?tid=73665)



Class 'CI_Controller' not found - Lucy789 - 05-20-2019

I try to call in system/core/Common.php next:
Code:
$ci =& get_instance();
$ci->load->library('session');
$userdetails = $ci->session->userdata('userdetails');

But I getting a fatal error: 
Code:
Class 'CI_Controller' not found in /system/core/CodeIgniter.php on line 233
 
I thought to connect directly:
Code:
require BASEPATH.'core/Controller.php';

But I getting other error:
Code:
Fatal error: Cannot redeclare class CI_Controller in /system/core/Controller.php on line 30


How I can getting session's data in Common.php ?


RE: Class 'CI_Controller' not found - Wouter60 - 05-20-2019

Never modify any files in the system folder or subfolders.
Only create or modify files in the application folder and it's subfolders.
The use the session library, autoload it in application/config/autoload.php or just load it into one of your controllers.

The $ci =& get_instance(); method is only necessary in libraries, not in controllers.
In a controller, you must use the $this object to refer to the controller's class.
Example:
PHP Code:
$this->load->library('session');
$this->session->userdetails 'test';
echo 
$this->session->userdetails;
unset(
$_SESSION['userdetails']); 



RE: Class 'CI_Controller' not found - Lucy789 - 05-21-2019

(05-20-2019, 01:30 PM)Wouter60 Wrote: Never modify any files in the system folder or subfolders.
Only create or modify files in the application folder and it's subfolders.

Thanks for the answer. But I need to modify the method in core/Common.php
I get in this method via a global variable $_SERVER the remote ip-address and I need to get data from database or from session and to record in log message.
Therefore, for me, the best way out would be to connect the session library to this method and get the data. But I think core/Controller declares later than Common.php and therefore I getting this error.


RE: Class 'CI_Controller' not found - InsiteFX - 05-21-2019

CodeIgniter User Guide - Hooks - Extending the Framework Core


RE: Class 'CI_Controller' not found - dave friend - 05-21-2019

(05-21-2019, 12:28 AM)Lucy789 Wrote:
(05-20-2019, 01:30 PM)Wouter60 Wrote: Never modify any files in the system folder or subfolders.
Only create or modify files in the application folder and it's subfolders.

Thanks for the answer. But I need to modify the method in core/Common.php
I get in this method via a global variable $_SERVER the remote ip-address and I need to get data from database or from session and to record in log message.
Therefore, for me, the best way out would be to connect the session library to this method and get the data. But I think core/Controller declares later than Common.php and therefore I getting this error.

I don't see that any of your requirements cannot be accomplished in the controller's constructor. You're going to have to provide more code and strong arguments for hacking the core.