Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
扩展codeigniter的多系统类_Codeigniter - Fatal编程技术网

扩展codeigniter的多系统类

扩展codeigniter的多系统类,codeigniter,Codeigniter,我想处理codeigniter上的错误,所以我需要扩展类CI_控制器和CI_异常,以便如何实现它。像下面这样。是否有可能对整个系统以钩子或其他方式全局处理错误 class Language extends CI_Controller , CI_Exceptions{ public function __construct() { parent::__construct(); parent::CI_Exceptions(); } } 关

我想处理codeigniter上的错误,所以我需要扩展类CI_控制器和CI_异常,以便如何实现它。像下面这样。是否有可能对整个系统以钩子或其他方式全局处理错误

class Language extends CI_Controller , CI_Exceptions{

    public function __construct()
    {
        parent::__construct();
        parent::CI_Exceptions();

    }
}
关于如何使用钩子实现这一点,有一个很好的解决方案。我从文章中复制了样本,但我会去那里阅读解决方案,以获得正确的方向

钩子

例外类


由于PHP不支持扩展多个类,您可以让CI_控制器扩展CI_异常,然后语言可以扩展CI_控制器,因为CI v2+应该是父类::_父类;。
$hook['pre_controller'][] = array(
                       'class'    => 'ExceptionHook',
                       'function' => 'SetExceptionHandler',
                       'filename' => 'ExceptionHook.php',
                       'filepath' => 'hooks'
                      );
class MY_Exceptions extends CI_Exceptions {

    public function __construct()
    {

        parent::CI_Exceptions();
    }

        public function show_php_error($severity, $message, $filepath, $line)
        {   
        $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
        $filepath = str_replace("\\", "/", $filepath);

        // For safety reasons we do not show the full file path
        if (FALSE !== strpos($filepath, '/'))
        {
                $x = explode('/', $filepath);
            $filepath = $x[count($x)-2].'/'.end($x);
        }

        if (ob_get_level() > $this->ob_level + 1)
        {
            ob_end_flush(); 
        }
        ob_start();
        include(APPPATH.'errors/error_php'.EXT);
        $buffer = ob_get_contents();
        ob_end_clean();

        $msg = 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line;

            log_message('error', $msg , TRUE);

        mail('dev-mail@example.com', 'An Error Occurred', $msg, 'From: test@example.com');  

        }

    }