0

I am running a php codeigniter based web application. I wanted to show custom error pages and custom error messages in my application.

So I extented the codeigniter's core Exception class with my custom exception class. I added a file MY_Exceptions.php in application/core folder.

It seems like the show_error method is overwritten but the show_php_error is not overwritten by my custom class. It is still executing the show_php_error method from system/core/Exceptions.php instead of application/core/MY_Exceptions.php (my custom class).

The MY_Exceptions.php file is as below -

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

}

1
  • Can you explain how you assured that just one method is ok? When show_php_error is called? Commented May 24, 2012 at 13:15

1 Answer 1

1

Why dont you just changed the "error_404.php" and "error_general.php" files in /application/errors?

That way you can style the pages however you want, and put your generic error messages there, rather than extending a core class?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.