无法找到指定的类:Codeigniter 中的 Session.php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29841942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to locate the specified class: Session.php in Codeigniter
提问by thais
The browser:
浏览器:
Unable to locate the specified class: Session.php
找不到指定的类: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.
当我将我的模型放在评论中时parent::__construct(); // $this->load->model('Chat_model');
,错误消失了。
This is my 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));
}
}
回答by Tpojka
class Chat_model extends CI_Controller
should be
应该
class Chat_model extends CI_Model
回答by Portable Page
If you use Codeigniter Modular Extensions HMVCthis error can occur if you forget to change your class to extend MX_Controller instead of CI_Controller
如果您使用 Codeigniter Modular Extensions HMVC,如果您忘记更改类以扩展 MX_Controller 而不是 CI_Controller,则可能会发生此错误
So in your case you would start your class with:
因此,在您的情况下,您将开始上课:
class Chat extends MX_Controller {}
Instead of:
代替:
class Chat extends CI_Controller {}
Hope this helps someone who runs into the same issue
希望这可以帮助遇到同样问题的人
回答by sandeep
Add changes into your library configurations in application/config/autoload.php file
将更改添加到 application/config/autoload.php 文件中的库配置中
$autoload['libraries'] = array('database', 'session');
and in application/config/config.php set the encryption key(any key u like)
并在 application/config/config.php 中设置加密密钥(您喜欢的任何密钥)
$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
如果您仍然遇到相同的错误,则将 System/library/Session/Session.php 复制到 System/library/ 文件夹,然后它应该可以工作
回答by Joey D
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+.
升级到 v3.0.6 后,我遇到了同样的问题,而且我确实已经正确设置了所有内容,因为这是一个刚刚升级到 v3+ 的现有站点。我的问题归结为我加载了“预控制器”的钩子。我的钩子适用于 CodeIgniter 的 v 2.0.X,但不适用于 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.
如果您在加载会话类之前加载钩子,并且您的钩子依赖于会话类,那可能是您的罪魁祸首。尝试将任何预控制器挂钩更改为后控制器,或将它们完全注释掉以查看是否能解决您的问题。这都位于 application/config/hooks.php 中。
回答by Sofyan Thayf
the question has been around long enough and has already gotten a solution, so I just shared experiences with similar cases.
这个问题已经存在了足够长的时间并且已经得到了解决方案,所以我只是分享了类似案例的经验。
I get the same error message when I involve the PDF library with the class name Pdf.phpand load it via autoload
as 'pdf'
.
当我使用类名为Pdf.php的 PDF 库并通过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.
我的错误,将显示我的页面的控制器也命名为Pdf.php,并且出现错误消息(这就是我发现这个问题的原因:))。在我将控制器的名称替换为另一个名称后,问题立即得到解决。
hope this useful
希望这有用
回答by Sathya Baman
Change your load library configuration in application/config/autoload.php
file
更改application/config/autoload.php
文件中的加载库配置
$autoload['libraries'] = array('database', 'session');
In application/config/config.php
set the encryption key(any key u like)
在application/config/config.php
设置加密密钥(U喜欢的任何键)
$config['encryption_key'] = 'thu23456789#[n,';
回答by Shahid Hussain Aali
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.
在我的例子中,库名和控制器类名是一样的,即我的控制器类名Ajaxer
和我的库类名是Ajaxer
. 我将我的库类名称更改为Ajaxer_lib
并解决了问题。
回答by mr_afry
In your Chat_model, try to change class Chat_model extends CI_Controller
to class Chat_model extends CI_Model
.
在您的 Chat_model 中,尝试更改class Chat_model extends CI_Controller
为class Chat_model extends CI_Model
.
回答by Clare D.
If none of the above solution worked, my workaround was:
如果上述解决方案均无效,我的解决方法是:
In my autoload config, I had a library called 'auth'.
在我的自动加载配置中,我有一个名为“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]
使用 [CodeIgniter v3]
回答by Deepak singh Thakur
Model Extends CI_Model Not CI_Controller class Chat_model extends CI_Model { ............. }
模型扩展 CI_Model 不是 CI_Controller 类 Chat_model 扩展 CI_Model { ........ }