用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3429|回复: 4
收起左侧

[HELP] 如何定制error_404

[复制链接]
发表于 2012-1-13 00:17:32 | 显示全部楼层 |阅读模式
我想在404页面中加入页头和页脚,如何在application/error/error_404.php中包含
application/view/下的文件
发表于 2012-1-13 07:16:43 | 显示全部楼层
视图静态的话  error_404.php 中直接include(APPPATH.'view/下的文件')

需要有变量传入的话 error_404.php 中调用 $CI =& get_instance();  获得你想要的数据 ,
然后$CI->load->view('视图',$数据);

..试试吧   同是新手 求教育
发表于 2012-1-13 10:11:25 | 显示全部楼层
你的应用程序目录下config里找到routes.php 内容如下:$route['default_controller'] = "welcome";
$route['404_override'] = 'error/error_404';

404是不是出来了。
error是控制器,error_404是功能(函数),然后你查以在error_404函数里实现你想要的加载header和footer 之类的。你想干什么就干什么吧
发表于 2012-1-13 10:16:16 | 显示全部楼层
贴一个我最近做的一个

controllers/error.php如下:
PHP复制代码
 
<?php
if (! defined ( 'BASEPATH' ))
        exit ( 'No direct script access allowed' );
 
class Error extends CI_Controller {
        function __construct() {
                parent::__construct ();
                $this->load->helper ( 'url' );
        }
       
        function index() {
                       
        }
        function error_404(){
                $data=array();
                $data['heading'] = "404 Page Not Found";
                $data['message'] = "The page you requested was not found.";
                $data['webmasteremail'] = $this->config->item ( 'webmasteremail');
                $this->load->view ( 'error/error_404', $data );
        }
}
 
 
复制代码

config/routes.php如下:
PHP复制代码
 
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
 
$route['default_controller'] = "welcome";
$route['404_override'] = 'error/error_404';
 
 
复制代码


views/error/error404.php如下:

HTML复制代码
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404 Page Not Found</title>
<style type=text/css>
body { font-size: 9pt; color: #842b00; line-height: 16pt; font-family: "tahoma", "宋体"; text-decoration: none }
table { font-size: 9pt; color: #842b00; line-height: 16pt; font-family: "tahoma", "宋体"; text-decoration: none }
td { font-size: 9pt; color: #842b00; line-height: 16pt; font-family: "tahoma", "宋体"; text-decoration: none }
body { scrollbar-highlight-color: buttonface; scrollbar-shadow-color: buttonface; scrollbar-3dlight-color: buttonhighlight; scrollbar-track-color: #eeeeee; background-color: #ffffff }
a { font-size: 9pt; color: #842b00; line-height: 16pt; font-family: "tahoma", "宋体"; text-decoration: none }
a:hover { font-size: 9pt; color: #0188d2; line-height: 16pt; font-family: "tahoma", "宋体"; text-decoration: underline }
h1 { font-size: 9pt; font-family: "tahoma", "宋体" }
</style>
</head>
<body topmargin=20>
<table cellspacing=0 width=600 align=center border=0 cepadding="0">
  <tbody>
    <tr colspan="2">
      <td valign=top align=middle><img height=100 src="<?=base_url()?>skin/404.jpg" width=100 border=0>
      <td>
      <td><h1>无法找到该页</h1>
        http 错误 404:您正在浏览的页面可能已经删除、更名或暂时不可用。
        <hr noshade size=0>
        <p>☉ 请尝试以下操作:</p>
        <ul>
          <li>确保浏览器的地址栏中显示的网站地址的拼写和格式正确无误。</li>
          <li>如果通过单击链接而到达了该网页,请与网站管理员联系,通知他们该链接的格式不正确。</li>
          <li>单击<a href="javascript:history.back(1)"><font color=#ff0000>后退</font></a>按钮尝试另一个链接。 </li>
        </ul>
        <p>☉Please try the following </p>
        <ul>
          <li>Ensure that the browser's address bar the website address is spelled and formatted correctly.</li>
          <li>If you reached by clicking a link to the website, please contact the site administrator to alert them that the link is incorrectly formatted.</li>
          <li>Click the <a href="javascript:history.back(1)"><font color=#ff0000>Back</font></a> button to try another link.</li>
        </ul>
        <a href="mailto:<?=$webmasteremail?>">发送邮箱:<?=$webmasteremail?></a> <a href="mailto:<?=$webmasteremail?>">Send E-mail:<?=$webmasteremail?></a>
         </td>
    </tr>
  </tbody>
</table>
</body>
</html>
 
 
复制代码

评分

参与人数 1威望 +5 收起 理由
Hex + 5 赞一个!

查看全部评分

 楼主| 发表于 2012-1-27 00:59:51 | 显示全部楼层
good

本版积分规则