Could not find the specified class: Session.php in Codeigniter

Browser:

Unable to find the specified class: Session.php

This is my controller:

<?php class Chat extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('Chat_model'); } public function index() { $this->view_data['chat_id'] = 1; $this->view_data['student_id'] = $this->session->userdata('student_id'); $this->view_data['page_content'] = 'chat'; $this->load->view('chat'); } public function ajax_addChatMessage() { $chat_id = $this->input->post('chat_id'); $student_id = $this->input->post('student_id'); $bericht = $this->input->post('chat_id', TRUE); $this->Chat_model->addChatMessage($chat_id, $student_id, $bericht); } } 

When I put my model in a comment in parent::__construct(); // $this->load->model('Chat_model'); parent::__construct(); // $this->load->model('Chat_model'); , the error has disappeared.

This is my Chat_model:

 <?php class Chat_model extends CI_Controller { public function Chat_model() { parent::__construct(); } public function addChatMessage($chat_id, $student_id, $bericht) { $query = "INSERT INTO tbl_chatberichten (chat_id, student_id, bericht) VALUES (?,?,?)"; $this->db->query($query, array($chat_id, $student_id, $bericht)); } } 
+6
source share
12 answers
 class Chat_model extends CI_Controller 

it should be

 class Chat_model extends CI_Model 
+16
source

If you use the Codeigniter Modular Extensions HMVC , this error may occur if you forget to change your class to extend MX_Controller instead of CI_Controller

So, in your case, you will start your class with:

 class Chat extends MX_Controller {} 

Instead:

 class Chat extends CI_Controller {} 

Hope this helps someone who is facing the same issue.

+13
source

Add changes to your library configuration in the file application / config / autoload.php

 $autoload['libraries'] = array('database', 'session'); 

and in the application /config/config.php set the encryption key (any u key)

 $config['encryption_key'] = 'thu23456789#[n,'; 

If you still get the same error, then copy System / library / Session / Session.php to System / library / folder, then it should work

+3
source

My solution: Preface: If you do not use hooks, this will not be a solution for you.

I had the same problem after upgrading to version 3.0.6, and I definitely set everything up correctly, as this is an existing site being updated to version v3 +. My problem came down to the hooks that I downloaded the "pre-controller". My hooks worked with v 2.0.X CodeIgniter, but not with v3 +.

If you load hooks before loading a session class, and your hook is dependent on the session class, this could be your culprit. Try changing any hooks in front of the controller to a post-controller, or completely comment them out to see if this fixes the problem. All this is in the / config / hooks.php application.

+2
source

Change the configuration of the download library in the file application/config/autoload.php

  $autoload['libraries'] = array('database', 'session'); 

In application/config/config.php set the encryption key (any u key)

  $config['encryption_key'] = 'thu23456789#[n,'; 
0
source

Add this instead of the chat controller constructor

  public function __construct() { parent::__construct(); $this->load->library('session'); $this->load->model('Chat_model'); } 

Loads a session library to your controller so you can use the methods.

0
source

Model extends CI_Model Not CI_Controller class Chat_model extends CI_Model {.............}

0
source

In my case, the library name and controller class name were the same. i. My controller name was Ajaxer , as well as the name of my Ajaxer library Ajaxer . I changed the class name of the library to Ajaxer_lib and solved the problem.

0
source

In your Chat_model, try changing the class Chat_model extends CI_Controller to the class Chat_model extends CI_Model .

0
source

If none of the above solutions worked, my workaround was:

In my autoload configuration, I had a library named "auth".

however, it somehow failed in my user controller because "auth" did not load automatically (I checked everything). Since I only use it when I log in, I removed it from the startup configuration and loaded it into my user controller.

I have never had this problem before, but suddenly one day it happened.

Using [CodeIgniter v3]

0
source

the question was long ago and already found a solution, so I just shared my experience with similar cases.

I get the same error message when I connect the PDF library with the class name Pdf.php and load it through autoload as 'pdf' .

My error, the controller that will display my page, I also called Pdf.php , and an error message appears (that's why I found this question :)). The problem was immediately resolved after I replaced the name of my controller with a different name.

hope this is helpful

0
source

Change your library configuration in application / config / autoload.php

 $autoload['libraries'] = array('database','ci_session'); 

Set the encryption key for your application in application / config / config.php

 $config['encryption_key'] = 'sdjfkdjkfj'; 

Copy system /libararies/Session/Session.php to application / libraries / Rename application / libraries / Session.php to CI_Session.php

Now the CI_Session object will be accessible through the bottom line

 $this->ci_session 
-2
source

All Articles