无法找到指定的类:Codeigniter中的Session.php

tha*_*ais 7 php model codeigniter

浏览器:

无法找到指定的类:Session.php

这是我的控制器:

<?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);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我把我的模型放在评论中时parent::__construct(); // $this->load->model('Chat_model');,错误消失了.

这是我的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));

    }

}
Run Code Online (Sandbox Code Playgroud)

Tpo*_*jka 16

class Chat_model extends CI_Controller
Run Code Online (Sandbox Code Playgroud)

应该

class Chat_model extends CI_Model
Run Code Online (Sandbox Code Playgroud)


小智 13

如果您使用Codeigniter Modular Extensions HMVC,如果您忘记更改类以扩展MX_Controller而不是CI_Controller,则会发生此错误

所以在你的情况下,你将开始你的课程:

class Chat extends MX_Controller {}
Run Code Online (Sandbox Code Playgroud)

代替:

class Chat extends CI_Controller {}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助遇到同样问题的人


Sof*_*ayf 5

这个问题已经存在了足够长的时间并且已经得到了解决方案,所以我只是分享了类似案例的经验。

当我使用类名为Pdf.php的 PDF 库并通过autoloadas加载它时,我收到相同的错误消息'pdf'

我的错误,将显示我的页面的控制器也命名为Pdf.php,并出现错误消息(这就是我发现这个问题的原因:))。在我将控制器的名称替换为另一个名称后,问题立即得到解决。

希望这有用


Sat*_*man 0

application/config/autoload.php更改文件中的加载库配置

  $autoload['libraries'] = array('database', 'session');
Run Code Online (Sandbox Code Playgroud)

设置application/config/config.php加密密钥(您喜欢的任何密钥)

  $config['encryption_key'] = 'thu23456789#[n,';
Run Code Online (Sandbox Code Playgroud)