Welcome Guest, Not a member yet? Register   Sign In
Class 'CI_Controller' not found
#1

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 ?
Reply
#2

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']); 
Reply
#3

(This post was last modified: 05-21-2019, 01:27 AM by Lucy789.)

(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.
Reply
#4

CodeIgniter User Guide - Hooks - Extending the Framework Core
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB