2013-02-28 126 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