如何在CodeIgniter中获取show_error()以加载视图? [英] How to get show_error() in CodeIgniter to load a view?

查看:124
本文介绍了如何在CodeIgniter中获取show_error()以加载视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在所有页面上加载正面图和正面图。但是 show_error 使用其自己的完整模板。并且它在加载此模板后停止执行,因此如果我愿意也不会加载页脚。

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 the footer wouldn't even load if I wanted to.

我应该重写此方法还是有其他方法?

Should I override this method or is there another way?

推荐答案

因此,这就是我的操作方式,并且效果很好。我按照Yan Berk的建议扩展了 CI_Exceptions ,但是我可以使用 get_instance 并加载我的视图。

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;  
}
}

这篇关于如何在CodeIgniter中获取show_error()以加载视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆