CodeIgniter:找不到类“CI_Controller" [英] CodeIgniter: Class 'CI_Controller' not found
问题描述
我通过在 Application/Core 文件夹中添加 MY_Controller.php 扩展了 CodeIgniter 控制器.它工作正常,但是现在当我在 Application/errors
的 error_404.php
页面上添加以下代码时,出现错误.
I've extended CodeIgniter controller by adding MY_Controller.php in Application/Core folder. It works fine, but Now when I add following code on error_404.php
page in Application/errors
, I get error.
导致问题的代码:
<?php $ci =& get_instance();?>
<?php $this->ci->load->view('header')?>
错误:
Fatal error: Class 'CI_Controller' not found in path osystemcoreCodeIgniter.php on line 231
systemcoreCodeIgniter.php
的第 231 行是:
The line 231 of the systemcoreCodeIgniter.php
is:
function &get_instance()
{
return CI_Controller::get_instance();
}
如何解决此问题,以便我可以在 error_404.php 中加载视图,而无需更改系统文件中的任何内容.
How can I fix this so that I can load view in the error_404.php without changing anything in system files.
附注.我使用的是最新版本.
PS. I'm using latest version.
谢谢.
推荐答案
我认为 CI_Controller 尚未加载.Exception 类使用 include
处理 404 页面输出.
I don't think CI_Controller is loaded yet. The Exception class is handling the 404 page output using an include
.
在过去,我曾经直接使用 include
来拼凑模板,或者对我的 404 页面 URL 执行 file_get_contents()
或 cURL 请求,但他们终于为此做了些什么.在 2.0 中,您可以在 routes.php
中定义自定义 404 页面:
In the old days, I used to use straight include
s to piece together a template, or do a file_get_contents()
or cURL request to my 404 page URL, but they finally did something about it. In 2.0 you can define a custom 404 page in routes.php
:
$route['404_override'] = 'controller/method/parameter';
它仍然不是完美的解决方案,但现在最简单的方法就是使用路线.
It's still not a perfect solution, but the easiest way now is just to use the route.
注意 base_url()."controller/method/parameter"
必须是一个有效的 url,并且你应该确保在输出页面的控制器中设置一个 404 标头(它不是由于某种原因自动完成).
Note that base_url()."controller/method/parameter"
must be a valid url, and you should make sure to set a 404 header in the controller that outputs the page too (it's not done automatically for some reason).
这篇关于CodeIgniter:找不到类“CI_Controller"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!