Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Codeigniter中显示自定义错误消息_Php_Codeigniter - Fatal编程技术网

Php 在Codeigniter中显示自定义错误消息

Php 在Codeigniter中显示自定义错误消息,php,codeigniter,Php,Codeigniter,我正在运行一个基于php codeigniter的web应用程序。我想在我的应用程序中显示自定义错误页面和自定义错误消息 因此,我用我的自定义异常类扩展了codeigniter的核心异常类。我在application/core文件夹中添加了一个文件MY_Exceptions.php 看起来show\u error方法被覆盖了,但是show\u php\u error并没有被我的自定义类覆盖。它仍然在执行system/core/Exceptions.php中的show_php_error方法,而不

我正在运行一个基于php codeigniter的web应用程序。我想在我的应用程序中显示自定义错误页面和自定义错误消息

因此,我用我的自定义异常类扩展了codeigniter的核心异常类。我在application/core文件夹中添加了一个文件MY_Exceptions.php

看起来
show\u error
方法被覆盖了,但是
show\u php\u error
并没有被我的自定义类覆盖。它仍然在执行system/core/Exceptions.php中的show_php_error方法,而不是application/core/MY_Exceptions.php(我的自定义类)

myu Exceptions.php文件如下所示-

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Exceptions extends CI_Exceptions
{
public function __construct()
{
    parent::__construct();
}

function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
    if($template!='error_404'){
        $template = 'custom_error_page';
        $heading = "An Error Occured";
        $message = "We're sorry, but we can not complete the action you requested. A notification has been sent to our customer service team. Please try again later.";
    }else{
        $template = 'custom_error_page';
        $heading = "404 Page Not Found";
        $message = "We're sorry, but we can not load the page you requested. A notification has been sent to our customer service team. Please try again later..";
    }
    set_status_header($status_code);

    $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';

    if (ob_get_level() > $this->ob_level + 1)
    {
        ob_end_flush();
    }
    ob_start();
    include(APPPATH.'errors/'.$template.'.php');
    $buffer = ob_get_contents();
    ob_end_clean();
    return $buffer;
}

function show_php_error($severity, $message, $filepath, $line)
{
    $heading = "An Error Occured";
    $message = " We're sorry, but we can not complete the action you requested. A notification has been sent to our customer service team. Please try again later.";
    echo $this->show_error($heading, $message, 'custom_error_php', 404);
    exit;
}

为什么不在/application/errors中更改“error\u 404.php”和“error\u general.php”文件


这样,您就可以随心所欲地设置页面样式,并将通用错误消息放在那里,而不是扩展一个核心类?

您能解释一下如何确保只使用一个方法就可以了吗?何时调用show_php_error?