1

I´m extending CodeIgniters core lib (Log) with a better threshold level and a way to mail serious errors. But i can´t read my config file from my library for some reason. If i can´t access my config....i can´t get the email addresses to mail to. What am i doing wrong? The message i get is: "Fatal error: Class 'CI_Controller' not found in..."

This is my code so far:

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');
}
}
2
  • See - stackoverflow.com/a/8774159/50913 - it might be of use. Commented Feb 28, 2013 at 16:37
  • That answer is more then a year old. And it didn´t help me. I can´t load anything from MY_Log. Not configs, no libraries. Nothing. The only thing i managed to do was to access the main config file with this: $config =& get_config(); That works. But it´s not my config. And i still would like to load the "Email" library in my library. Commented Feb 28, 2013 at 16:54

1 Answer 1

1

I think it's because this class (Log/MY_Log) is being loaded too early in the application life cycle and get_instance() isn't available.

Perhaps instead of extending the build in logging functionality you could write your own class to handle such logging (If you do so you could wrap it up and release it as a spark :) )

Alternatively you could use a composer package to provide you with the functionality you are after as I am sure there is one that already exists.

If your not familiar with composer I'd recommend reading Phil Sturgeon's article.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.