2013-02-28 104 views
1

我正在使用更好的阈值级别扩展CodeIgniters核心库(Log)并以邮件方式发送严重错误。但由于某种原因,我无法从我的库中读取我的配置文件。如果我不能访问我的配置....我无法获取邮件地址。我究竟做错了什么?我得到的消息是:“致命错误:类‘是CI_Controller’中找不到......”Codeigniter:从自定义库中获取自定义配置文件?

这是我到目前为止的代码:

class MY_Log extends CI_Log { 
/** 
* Constructor 
* 
* @access public 
*/ 
function MY_Log() 
{ 
    parent::__construct(); 
    $this->_levels = array('ERROR' => '1', 'INFO' => '2', 'DEBUG' => '3', 'ALL' => '4'); 
} 

/** 
* Write Log File 
* 
* Calls the native write_log() method and then sends an email if a log message was generated. 
* 
* @access public 
* @param string the error level 
* @param string the error message 
* @param bool whether the error is a native PHP error 
* @return bool 
*/ 
function write_log($level = 'error', $msg, $php_error = FALSE) 
{ 
    $result = parent::write_log($level, $msg, $php_error); 

    $this->ci =& get_instance(); 
    $this->ci->load->config('myconf/mailconf'); 
    echo $this->ci->config->item('emails'); 
} 
} 
+0

请参阅 - http://stackoverflow.com/a/8774159/50913 - 它可能是有用的。 – Malachi 2013-02-28 16:37:48

+0

答案已经过去了一年多。它并没有帮助我。我无法从MY_L​​og加载任何内容。没有配置,没有库。没有。我设法做的唯一事情就是用这个访问主配置文件:$ config =&get_config();这样可行。但这不是我的配置。我仍然想在我的图书馆中加载“电​​子邮件”库。 – Juw 2013-02-28 16:54:23

回答

1

我想这是因为这个类(Log/MY_Log)正在应用程序生命周期中过早加载并且get_instance()不可用。

也许,而不是在扩展日志记录功能构建,你可以编写自己的类来处理这样的记录(如果你这样做,你可以把它包起来,释放它作为一个spark :))

另外,您可以使用一个composer package为您提供您以后的功能,因为我确信有一个已经存在的功能。

如果你不熟悉作曲家,我会推荐阅读Phil Sturgeon's article