CI_Exceptions::show_php_error PHP Method

show_php_error() public method

Native PHP error handler
public show_php_error ( integer $severity, string $message, string $filepath, integer $line ) : string
$severity integer Error level
$message string Error message
$filepath string File path
$line integer Line number
return string Error page output
    public function show_php_error($severity, $message, $filepath, $line)
    {
        $templates_path = config_item('error_views_path');
        if (empty($templates_path)) {
            $templates_path = VIEWPATH . 'errors' . DIRECTORY_SEPARATOR;
        }
        $severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
        // For safety reasons we don't show the full file path in non-CLI requests
        if (!is_cli()) {
            $filepath = str_replace('\\', '/', $filepath);
            if (FALSE !== strpos($filepath, '/')) {
                $x = explode('/', $filepath);
                $filepath = $x[count($x) - 2] . '/' . end($x);
            }
            $template = 'html' . DIRECTORY_SEPARATOR . 'error_php';
        } else {
            $template = 'cli' . DIRECTORY_SEPARATOR . 'error_php';
        }
        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();
        echo $buffer;
    }

Usage Example

Ejemplo n.º 1
0
 public function show_php_error($severity, $message, $filepath, $line)
 {
     $ci =& get_instance();
     // this allows different params for different environments
     $ci->config->load('email_php_errors');
     // if it's enabled
     if (config_item('email_php_errors')) {
         // set up email with config values
         $ci->load->library('email');
         $ci->email->from(config_item('php_error_from'));
         $ci->email->to(config_item('php_error_to'));
         // set up subject
         $subject = config_item('php_error_subject');
         $subject = $this->_replace_short_tags($subject, $severity, $message, $filepath, $line);
         $ci->email->subject($subject);
         // set up content
         $content = config_item('php_error_content');
         $content = $this->_replace_short_tags($content, $severity, $message, $filepath, $line);
         // set message and send
         $ci->email->message($content);
         $ci->email->send();
     }
     $msg = 'Severity: ' . $severity . '  --> ' . $message . ' ' . $filepath . ' ' . $line;
     // do the rest of the codeigniter stuff
     parent::show_php_error($severity, $message, $filepath, $line);
 }
All Usage Examples Of CI_Exceptions::show_php_error