找不到codeigniter 3.0自定义404错误页面 [英] codeigniter 3.0 custom 404 not found error page
问题描述
我的问题是关于升级到Codeigniter 3.0之后的自定义错误页面.
My problem is about custom error pages after upgrading to Codeigniter 3.0.
我以前有一个Errors
控制器,用于处理网站的404错误页面-在该控制器上,我自定义了页面的某些部分,例如,如果用户登录,在导航栏上显示用户名等.(是,在404错误页面上).
I used to have a Errors
controller which handled 404 error page of the website - on this controller I have customized some parts of page, such as if user is logged in, it was showing username on the navigation bar and etc. (yes, on 404 error page).
升级到CI 3.0后,我注意到错误页面在其他文件夹中处理,我开始迁移到这种方式.但是问题是我无法在此页面上加载任何变量,例如会话变量,甚至无法在这些页面上使用任何CI的功能.
After upgrading to CI 3.0, I have noticed that error pages are handled in different folder, I started to migrate to this way; but the problem is I can't load any variables to this page, such as session variables or can't even use any CI's functions on these pages.
我认为该页面应该只是HTML页面,但是有什么方法可以将变量加载到这些错误页面上?
I think this pages are supposed to be only HTML pages, but is there any way to load variables to these error pages?
推荐答案
您需要在application/config/routes.php
中设置以下路线
You need to set in application/config/routes.php
the following route
$route['404_override'] = 'my404';
然后您需要在controllers目录(application/controllers/)
Then you need to create a new controller in your controllers directory (application/controllers/)
<?php
class My404 extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->output->set_status_header('404');
$this->load->view('err404');//loading in custom error view
}
}
并创建一个err404
视图.就是这样!
And create an err404
view. Thats all!
参考:保留的路线
这篇关于找不到codeigniter 3.0自定义404错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!