2012-05-24 4 views
0

나는 PHP 코드 기자 기반 웹 응용 프로그램을 실행 중입니다. 내 응용 프로그램에 사용자 정의 오류 페이지 및 사용자 정의 오류 메시지를 표시하려고했습니다.Codeigniter에 사용자 정의 오류 메시지 표시

그래서 코드 네이 터의 핵심 Exception 클래스를 내 사용자 정의 예외 클래스로 확장했습니다. application/core 폴더에 MY_Exceptions.php 파일을 추가했습니다.

show_error 메서드를 덮어 쓰지 만 show_php_error은 내 사용자 지정 클래스로 덮어 쓰지 않습니다. application/core/MY_Exceptions.php (내 사용자 정의 클래스) 대신 system/core/Exceptions.php에서 show_php_error 메소드를 실행하고 있습니다.

MY_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; 
} 

} 방금/응용 프로그램/오류에서 "error_404.php"와 "error_general.php"파일을 변경 해달라고 왜

+0

한 가지 방법이 좋다고 어떻게 확신 할 수 있습니까? show_php_error가 호출되면? –

답변

1

?

그런 식으로 원하는대로 페이지 스타일을 지정할 수 있으며 핵심 클래스를 확장하지 않고 일반 오류 메시지를 그 곳에 넣을 수 있습니까?

관련 문제