【发布时间】:2015-07-02 17:31:52
【问题描述】:
浏览器:
找不到指定的类: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);
}
}
当我将我的模型放在 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));
}
}
【问题讨论】:
-
那么你的问题出在模型上吧?你能告诉我们你在那里得到的代码吗?是否构建了父模型类?
-
我在我的问题中添加了它
-
你能用
__construct()代替Chat_model()吗? Codeigniter 推荐它,也许这就是问题所在。 -
$this->load->library('session');在您的控制器父构造函数中编写此代码并尝试
-
按照你们说的做了,还是一样的错误
标签: php codeigniter model