问题描述
我已经通过在Application / Core文件夹中添加MY_Controller.php来扩展CodeIgniter控制器。它工作正常,但现在,当我在 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\to\system\core\CodeIgniter.php on line 231
system\core\CodeIgniter.php
的第231行是: p>
The line 231 of the system\core\CodeIgniter.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。我使用的是最新版本。
PS. I'm using latest version.
感谢。
推荐答案
不认为CI_Controller已加载。异常类使用 include
来处理404页面输出。
I don't think CI_Controller is loaded yet. The Exception class is handling the 404 page output using an include
.
在过去,直接包括
来组合模板,或对我的404页面网址执行 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.
c $ c> 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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!