CI_Exceptions::show_error PHP Method

show_error() public method

Takes an error message as input (either as a string or an array) and displays it using the specified template.
public show_error ( string $heading, string | string[] $message, string $template = 'error_general', integer $status_code = 500 ) : string
$heading string Page heading
$message string | string[] Error message
$template string Template name
$status_code integer (default: 500)
return string Error page output
    public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
    {
        $templates_path = config_item('error_views_path');
        if (empty($templates_path)) {
            $templates_path = VIEWPATH . 'errors' . DIRECTORY_SEPARATOR;
        }
        if (is_cli()) {
            $message = "\t" . (is_array($message) ? implode("\n\t", $message) : $message);
            $template = 'cli' . DIRECTORY_SEPARATOR . $template;
        } else {
            set_status_header($status_code);
            $message = '<p>' . (is_array($message) ? implode('</p><p>', $message) : $message) . '</p>';
            $template = 'html' . DIRECTORY_SEPARATOR . $template;
        }
        if (ob_get_level() > $this->ob_level + 1) {
            ob_end_flush();
        }
        ob_start();
        include $templates_path . $template . '.php';
        $buffer = ob_get_contents();
        ob_end_clean();
        return $buffer;
    }

Usage Example

 /**
  * Display an error message
  *
  * @access	public
  * @param	string	the error message
  * @param	string	any "swap" values
  * @param	boolean	whether to localize the message
  * @return	string	sends the application/error_db.php template		
  */
 function display_error($error = '', $swap = '', $native = FALSE)
 {
     $LANG = new CI_Language();
     $LANG->load('db');
     $heading = 'MySQL Error';
     if ($native == TRUE) {
         $message = $error;
     } else {
         $message = !is_array($error) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
     }
     if (!class_exists('CI_Exceptions')) {
         include BASEPATH . 'libraries/Exceptions' . EXT;
     }
     $error = new CI_Exceptions();
     echo $error->show_error('An Error Was Encountered', $message, 'error_db');
     exit;
 }
All Usage Examples Of CI_Exceptions::show_error