0

I am trying to extend the CodeIgniter controller. I have created MY_Controller.php file, the content of the file is as following:

<?php
class MY_Controller extends CI_Controller 
{ 
    function generate_key()
    {
        $n = rand(10e16, 10e20);
        return base_convert($n, 10, 36);
    }

Now I create my controllers by extending MY_Controller instead of CI_Controller. Following is an example of a controller:

class Member extends MY_Controller
{
    public function index()
    {
    $this->load->view('welcome');
    }

I have placed the MY_Controller.php file in the Application/libraries/ folder. But when I load the application, I get the error:

Fatal error: Class 'MY_Controller' not found in path\to\application\controllers\member.php

Can someone tell me what i am doing wrong? Thanks.

Edit: I'm using CodeIgniter 2.0.2

tereško
  • 58,060
  • 25
  • 98
  • 150
Roman
  • 3,764
  • 21
  • 52
  • 71

3 Answers3

4

I had been this issue:

`Fatal error: Class 'MY_Controller' not found ...`

publishing to my remote Linux server (DreamHost) but not on locally on Windows. The issue was Linux being case sensitive: I had MY_Controller.php with a lowecase c and it wasn't autoloading.

Just in case anyone else has the same issue :)

benedict_w
  • 3,543
  • 1
  • 32
  • 49
3

You need to create MY_Controller.php in application/core. I tried what you have setup and got the same problem. Moving the custom controller to core solved the problem.

Hope it helps!

Sukumar
  • 3,502
  • 3
  • 26
  • 29
1

I had problem like this,After some search I found error was made myself,Because my controller class name was MY_Controller but file name was My_Controller[Case not matching]. Note:- In localhost I didnt have any error.

In extended controller I Use

class Home  extends MY_Controller{
 function __construct() {
parent::__construct();
 }
}

even I got the error.

After changing my file name to MY_Controller it started to work well.

MY_contrller places in application/core folder.

falsarella
  • 12,217
  • 9
  • 69
  • 115
shihabudheen
  • 303
  • 1
  • 5
  • 11
  • for those having issues with this but who are following the correct directory listings/practices ^THIS is the answer. check those cases!! – John Blythe Oct 21 '13 at 19:26