Search code examples
phpcodeignitercodeigniter-2

How can I get CodeIgniter 2.1.4 to load my extended Controller Class?


I have looked for this answer all through stackoverflow and none have been able to help me.

my file name is: application/core/MY_Controller.php

class MY_Controller extends CI_Controller {

/**
 * Constructor
 */
public function __construct()
{
        parent::__construct();

}

}

I made a post in this thread asking if anyone had found an answer. I tried everything in that thread, and in all suggested links.

I'm at a complete loss.

Everything works on my local WAMP server (apache 2.4 php 5.4) and not on the production server (Ubuntu 12.04, apache 2.4, php 5.5)

error:

PHP Fatal error: Class 'MY_Controller' not found in filepath/application/controllers/welcome.php on line 7.

Line 7 is where I define the class: class welcome extends MY_Controller {

EDIT Thanks for all the help. I figured out what was wrong. When I initially started trying to figure out this problem, I noticed that I did not have my case right on the name of MY_Controller.php, it was My_Controller.php.

So, what I found out was that even though I changed the name of the file on my local machine, when I uploaded it, the name still didn't change. So, when I went to change it to all lower case I decided to do that directly on the production server and found that after all this time it was still named with the lowercase y when I thought I had changed that. I hope this helps anyone else who migrates from a WAMP environment to a LAMP environment to know that even though the case is changed, it is still the same name, and may or may not be changed when you upload it.


Solution

  • please go to your application/config/config.php and on the bottom insert this code

    function __autoload($class)
    {
     if(strpos($class, 'CI_') !== 0)
     {
      @include_once( APPPATH . 'core/'. $class . EXT );
     }
    }
    

    Now you are good to go.


    please try creating file MY_Controller.php in /core folder with this body

    class MY_Controller extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
            $this->output->enable_profiler(TRUE);
        }
    
    }
    

    and use welcome controller if it works.


    I missed note: Everything works on my local WAMP server (apache 2.4 php 5.4) and not on the production server (Ubuntu 12.04, apache 2.4, php 5.5)

    Please check your case of files/controllers

    Please try editing/renaming everything in to lower case (even my_controller extends CI_Controller).