How to get show_error() in CodeIgniter to load a view?

后端 未结 2 1296
离开以前
离开以前 2021-01-21 19:04

I need to load a head view and a foot view in all my pages. But show_error uses its own complete template. And it stops execution after it loads this template, so t

2条回答
  •  逝去的感伤
    2021-01-21 19:13

    So, this is how I did it, and it worked perfectly. I extended CI_Exceptions as suggested by Yan Berk, but I was able to use get_instance AND load my view.

    class MY_Exceptions extends CI_Exceptions {
    private $CI;
    private $dist;
    
    public function __construct() {
        parent::__construct();
        $this->CI =& get_instance();
        $this->dist = $this->CI->config->item('dist');
    }
    
    function show_error($heading, $message, $template = 'error_general', $status_code = 500) {
        $head_data = array("title"=>$this->dist['site_title'].": Error");
        $head = $this->CI->load->view('head', $head_data, TRUE);
        $body = $this->CI->load->view('error_body', $message, TRUE);
    
        echo $head;
        echo $body;  
    }
    }
    

提交回复
热议问题