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
 /**
  * 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;
 }
 function show_error($heading, $message, $template = 'error_general', $status_code = 500)
 {
     if (!is_null($CI =& get_instance()) and $status_code >= 500) {
         $error_data['heading'] = $heading;
         $error_data['message'] = is_array($message) ? '<pre>' . print_r($message, TRUE) . '</pre>' : $message;
         $CI->load->helper('email');
         report_error($template, $error_data);
     }
     return parent::show_error($heading, $message, $template, $status_code);
 }
 function show_error($heading, $message, $template = 'error_general', $status_code = 500)
 {
     if (ENVIRONMENT === 'production') {
         if ($status_code == 500) {
             $this->_report_error($message);
         }
         return parent::show_error("Wakakak", "lalalal", $template = 'error_general', $status_code = 500);
     } else {
         return parent::show_error($heading, $message, $template = 'error_general', $status_code = 500);
     }
 }
 /**
  * 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
  * @param 	int		the status code
  * @return	string
  */
 function show_error($heading, $message, $template = 'error_general', $status_code = 500)
 {
     if ($this->input->is_ajax_request()) {
         set_status_header($status_code);
         $message = $heading . "\n\n" . implode("\n", !is_array($message) ? array($message) : $message) . "\n";
         $this->output->json($status_code, $message);
         if (ob_get_level() > $this->ob_level + 1) {
             ob_end_clean();
         }
         ob_start();
         $this->output->_display();
         $buffer = ob_get_contents();
         ob_end_clean();
         return $buffer;
     } else {
         return parent::show_error($heading, $message, $template, $status_code);
     }
 }
Example #5
0
 function _remap($method)
 {
     // This page has been routed to with pages/view/whatever
     if ($this->uri->rsegment(1, '') . '/' . $method == 'pages/view') {
         $url_segments = $this->uri->total_rsegments() > 0 ? $this->uri->rsegment_array() : array($this->default_segment);
         $url_segments = array_slice($url_segments, 2);
     } else {
         $url_segments = $this->uri->total_segments() > 0 ? $this->uri->segment_array() : array($this->default_segment);
     }
     // Fetch this page from the database via cache
     $page = $this->cache->model('pages_m', 'get_by_path', array($url_segments));
     // If page is missing or not live (and not an admin) show 404
     if (!$page || $page->status == 'draft' && !$this->user_lib->check_role('admin')) {
         // Try and get an error page. If its been deleted, show nasty 404
         if (!($page = $this->cache->model('pages_m', 'get_by_path', array('404')))) {
             log_message('error', '404 Page Not Found --> ' . implode('/', $url_segments));
             $EXP = new CI_Exceptions();
             echo $EXP->show_error('', '', 'error_404', 404);
             exit;
         }
     }
     // 404 page? Set the right status
     if ($page->slug == '404') {
         $this->output->set_status_header(404);
     }
     // Not got a meta title? Use slogan for homepage or the normal page title for other pages
     if ($page->meta_title == '') {
         $page->meta_title = $this->viewing_homepage ? $this->settings->item('site_slogan') : $page->title;
     }
     // If the GET variable isbasic exists, do not use a wrapper
     if (!($page->layout = $this->page_layouts_m->get($page->layout_id))) {
         // Some pillock deleted the page layout, use the default and pray to god they didnt delete that too
         $page->layout = $this->page_layouts_m->get(1);
     }
     // Parser does not need ALL information for this bit, and I hate the Dwoo object syntax
     $page_array = array('page' => (array) $page);
     // Parse the layout string and output
     $page->layout->body = $this->parser->string_parse(stripslashes($page->layout->body), $page_array, TRUE);
     // Define data elements
     $this->data->page =& $page;
     $this->data->page->layout = $page->layout;
     // Create page output
     $this->template->title($page->meta_title)->set_metadata('keywords', $page->meta_keywords)->set_metadata('description', $page->meta_description)->build('index', $this->data);
 }
Example #6
0
 /**
  * 404 method
  * @access public
  * @param array $url_segments The URL segments
  * @return void
  */
 public function _404($url_segments)
 {
     // Try and get an error page. If its been deleted, show nasty 404
     if (!($page = $this->cache->model('pages_m', 'get_by_path', array('404')))) {
         log_message('error', '404 Page Not Found --> ' . implode('/', $url_segments));
         $EXP = new CI_Exceptions();
         echo $EXP->show_error('', '', 'error_404', 404);
         exit;
     }
     return $page;
 }
Example #7
0
 /**
  * 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)
 {
     // If we are in production, then lets dump out now.
     if (IN_PRODUCTION) {
         return parent::show_error($heading, $message, $template, $status_code);
     }
     if (!headers_sent()) {
         set_status_header($status_code);
     }
     $trace = debug_backtrace();
     $file = NULL;
     $line = NULL;
     $is_from_app = FALSE;
     if (isset($trace[1]['file']) and strpos($trace[1]['file'], APPPATH) === 0) {
         $is_from_app = !self::is_extension($trace[1]['file']);
     }
     // If the application called show_error, don't output a backtrace, just the error
     if ($is_from_app) {
         $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;
     }
     $message = implode(' / ', !is_array($message) ? array($message) : $message);
     // If the system called show_error, so lets find the actual file and line in application/ that caused it.
     foreach ($trace as $call) {
         if (isset($call['file']) and strpos($call['file'], APPPATH) === 0 and !self::is_extension($call['file'])) {
             $file = $call['file'];
             $line = $call['line'];
             break;
         }
     }
     unset($trace);
     self::exception_handler(new ErrorException($message, E_ERROR, 0, $file, $line));
     return;
 }
/**
* 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)
{
    if (!class_exists('CI_Exceptions')) {
        include_once BASEPATH . 'libraries/Exceptions.php';
    }
    $error = new CI_Exceptions();
    echo $error->show_error('An Error Was Encountered', $message);
    exit;
}