Roel
Roel

Reputation: 1472

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.

Upvotes: 2

Views: 11094

Answers (4)

Mitya
Mitya

Reputation: 34556

In case this helps anyone, I had the same problem and noticed that it occurred only on URLs that contained a + in them, e.g. as part of a permalink. CI went haywire; I prevented + signs from appearing in URLs, and all was well.

Upvotes: 0

Philipp Michael
Philipp Michael

Reputation: 954

I guess this error occurs when a log library function is called before CI_Controller class is loaded. This could happen in an early stage of your application routine. So you should extend the log library without using $this->$CI =& get_instance();.

Upvotes: 4

mitcheljh
mitcheljh

Reputation: 170

Try putting this at the top of MY_Log.php if you haven't already:

<?php defined('BASEPATH') OR exit('No direct script access allowed');

It's possible that your class MY_Log isn't actually being parsed by php if it's not included in the php delimiters. If that's the case, then CI would see the file MY_Log.php, and expect CI_Log to be extended by the class declared in MY_Log.php. But, if your class isn't within PHP delimiters, CI_Log wouldn't actually be extended, which could cause odd errors.

Upvotes: 0

Damien Pirsy
Damien Pirsy

Reputation: 25435

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.

Upvotes: 3

Related Questions