Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

    }

}
like image 329
thais Avatar asked Apr 24 '15 08:04

thais


4 Answers

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.

like image 70
Sofyan Thayf Avatar answered Nov 19 '22 03:11

Sofyan Thayf


class Chat_model extends CI_Controller

should be

class Chat_model extends CI_Model
like image 20
Tpojka Avatar answered Nov 19 '22 03:11

Tpojka


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 {}
like image 43
Portable Page Avatar answered Nov 19 '22 01:11

Portable Page


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

like image 4
sandeep Avatar answered Nov 19 '22 03:11

sandeep