Search code examples
phpcodeigniterextend

CodeIgniter CI_Controller not found


So basically, the below is the code I have right now:

class MY_Log extends CI_Log {

    /**
    * Variable storing the CodeIgniter instance.
    *
    * @access private
    * @since v0.1.0.0
    */
    private $CI;

    /**
    * Constructor for later use by internal
    * methods.
    *
    * @access public
    * @since v0.1.0.0
    */
    public function __construct()
    {
        // Extend the parent logging.
        parent::__construct();

        $this->$CI =& get_instance();
    }
}

And I get the following error;

Fatal error: Class 'CI_Controller' not found in /<deleted>/system/core/CodeIgniter.php on line 233

This is kinda how the user guide describes it.


Solution

  • Quite strange. I just replicated your case (with the info provided) and I encountered no problems. But make sure of a couple things:

    1. Your file is named MY_Log.php, and is located in application/libraries/My_log.php
    2. The file extends the parent class, in this case CI_Log
    3. You call the library in your controller as

      $this->load->library('log');
      $this->log->do_something();
      

      i.e, not using "My_log" but the parent library's name. In fact, you're extending it, not creating a different one, so CI wants you to call it the same as the original

    4. Your original file has the following line correctly written (without the $ sign before CI)

      $this->CI =& get_instance();
      

    My test case with your code provided works fine on my development machine (Windows 7 WAMP php 5.3.8). I'll be waiting for more infos.