在CodeIgniter中显示404错误的视图 [英] Display a view for 404 error in CodeIgniter

查看:83
本文介绍了在CodeIgniter中显示404错误的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CodeIgniter有一个非常简单的默认错误404消息:

The CodeIgniter has a very simple default error 404 message:

404 Page Not Found
The page you requested was not found.

不要在完全空白的页面上使用此错误消息,我想将此邮件包含在我的标题和页脚视图,以便错误消息具有相似的外观到其他页面。

Instead of using this error message on totally blank page, I want to wrap this message in between my header and footer view, so that the error message have similar look to the other pages.

为此,我创建了一个错误视图?例如:

For that purpose, I have created an error view? For example:

my404_view.php

<? $this->load->view('header'); ?>
404 Page Not Found
The page you requested was not found.
<? $this->load->view('footer'); ?>

现在,我如何使用 my404_view.php 作为默认视图显示404消息,而不是使用CodeIgniter默认错误消息。

Now, How can I use this my404_view.php as a default view to display 404 messages instead of using the CodeIgniter default error message.

推荐答案

php。例如:application / config / routes.php中的

You should change your routes.php. For example:

$route['404_override'] = 'welcome/_404';



in application/controllers/welcome.php

function _404(){
    $this->load->view("my404_view");
}

这在CI的当前版本中应该足够了。

And this should be sufficient in the current version of CI.

这篇关于在CodeIgniter中显示404错误的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆