thais
thais

Reputation: 133

Unable to locate the specified class: Session.php in Codeigniter

The browser:

Unable to locate 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 comment in the parent::__construct(); // $this->load->model('Chat_model'); the error is gone.

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));

    }

}

Upvotes: 11

Views: 82676

Answers (13)

can
can

Reputation: 11

I encountered with same error. I attached "session" on ---> yourproject/application/config/autoload.php

$autoload['drivers'] = array("session");

Upvotes: 1

Portable Page
Portable Page

Reputation: 239

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

So in your case you would start your class with:

class Chat extends MX_Controller {}

Instead of:

class Chat extends CI_Controller {}

Upvotes: 15

Sofyan Thayf
Sofyan Thayf

Reputation: 1328

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

My mistake, the controller that will display my page I also named Pdf.php, and the error message appears ( that's the reason why I found this question :) ). The problem was immediately solved after I replaced the name of my controller with another name.

Upvotes: 7

Clare D.
Clare D.

Reputation: 21

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

In my autoload config, I had a library called 'auth'.

however, in my custom controller, somehow it was being messed up because 'auth' wasn't being auto-loaded(I've checked everything). Since I am only using it when logging in, I removed it from my autoload config and load it in my custom controller.

I never had this issue before but suddenly one day it happened.

Using [CodeIgniter v3]

Upvotes: 0

mr_afry
mr_afry

Reputation: 1

In your Chat_model, try to change class Chat_model extends CI_Controller to class Chat_model extends CI_Model.

Upvotes: 0

Shahid Hussain Aali
Shahid Hussain Aali

Reputation: 11

In my case the library name and controller class name was same i.e my controller class name was Ajaxer and also my library class name was Ajaxer. I changed my library class name to Ajaxer_lib and its resolved the issue.

Upvotes: 0

iamguni
iamguni

Reputation: 29

Modify your library configurations in application/config/autoload.php file

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

Set the encryption key for your applicatiion 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, CI_Session object will be available through below line

$this->ci_session

Upvotes: -2

Deepak singh Thakur
Deepak singh Thakur

Reputation: 299

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

Upvotes: -1

Joey D
Joey D

Reputation: 21

My solution: Preface: If you don't use hooks, this will not be the solution for you.

I had this same issue, after upgrading to v3.0.6, and I definitely had everything setup correctly, as this is an existing site just being upgraded to v3+. My issue boiled down to hooks that I had loading 'pre-controller'. My hooks worked with v 2.0.X of CodeIgniter, but not with v3+.

If you are loading hooks before the session class is loaded, and your hook has a dependency on the session class, that may be your culprit. Try changing any pre-controller hooks to post-controller, or commenting them out completely to see if that fixes your issue. This is all located in application/config/hooks.php.

Upvotes: 2

sandeep
sandeep

Reputation: 152

Add changes into your library configurations in application/config/autoload.php file

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

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

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

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

Upvotes: 4

Tpojka
Tpojka

Reputation: 7111

class Chat_model extends CI_Controller

should be

class Chat_model extends CI_Model

Upvotes: 19

Harigovind R
Harigovind R

Reputation: 826

Add this instead of your Chat controller constructor

 public function __construct() {

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

This loads the session library to your controller so that you can use the methods.

Upvotes: -1

Sathya Baman
Sathya Baman

Reputation: 3515

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

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

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

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

Upvotes: 0

Related Questions