04-11-2011, 01:55 AM
[eluser]JayKae[/eluser]
So I have been trying to extend the default CI_Exceptions class. But what is driving me crazy is that it isn't working properly.
I'm using CI 2.0.2 excerpt below is from system/core/Exceptions.php
Adding some debug logic was my only change to the function. I thought it might be something I was doing wrong, so I renamed MY_Exceptions.php to something else so it is not coming into play.
Simply callingresults in the following output
I found the reason that it isn't working. In system/core/Common.php the following method is declared.
The function signatures aren't the same and that is what is causing the issue. I am assuming this is an oversight and I should file a bug report but I want to make sure that I haven't overlooked anything, I'm only 4 days into learning CI.
So I have been trying to extend the default CI_Exceptions class. But what is driving me crazy is that it isn't working properly.
I'm using CI 2.0.2 excerpt below is from system/core/Exceptions.php
Code:
/**
* General Error Page
*
* This function takes an error message as input
* (either as a string or an array) and displays
* it using the specified template.
*
* @access private
* @param string the heading
* @param string the message
* @param string the template name
* @return string
*/
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
// My debugging logic starts here
print('Heading: '.$heading);
echo '<br>';
print('Message: '.$message);
echo '<br>';
print($template);
echo '<br>';
print($status_code);
echo '<br>';
// Debug logic ends here
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.EXT);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
Adding some debug logic was my only change to the function. I thought it might be something I was doing wrong, so I renamed MY_Exceptions.php to something else so it is not coming into play.
Simply calling
Code:
show_error('$heading', '$message', '$template', 404);
Quote: Heading: $template
Message: $heading
error_general
$message
Heading: An Error Was Encountered
Message: Status codes must be numeric
error_general
500
An Error Was Encountered
Status codes must be numeric
I found the reason that it isn't working. In system/core/Common.php the following method is declared.
Code:
/**
* Error Handler
*
* This function lets us invoke the exception class and
* display errors using the standard error template located
* in application/errors/errors.php
* This function will send the error page directly to the
* browser and exit.
*
* @access public
* @return void
*/
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
$_error =& load_class('Exceptions', 'core');
echo $_error->show_error($heading, $message, 'error_general', $status_code);
exit;
}
// ------------------------------------------------------------------------
The function signatures aren't the same and that is what is causing the issue. I am assuming this is an oversight and I should file a bug report but I want to make sure that I haven't overlooked anything, I'm only 4 days into learning CI.