codeigniter MY_Controller not found

后端 未结 5 407
误落风尘
误落风尘 2021-01-02 10:58

i’m using the Codeigniter.2.1.3 for a website, so i need to extend the CI_Controller so i can add a method to be executed with all controllers so i did what’s in the user_gu

相关标签:
5条回答
  • 2021-01-02 11:37

    Late with this answer, but I got the

    "Fatal error: Class ‘MY_Controller’ not found" error

    when I had a controller (.php) file by the same name at the web root instead of the application/controllers directory.

    Don't know how it got there, actually, but the problem went away when I deleted it.

    0 讨论(0)
  • 2021-01-02 11:38

    $config['subclass_prefix'] = "MY_"

    check that in config.php and of course you should use it in Controller Name Like MY_Controller.php and Named "class MY_Controller...."

    0 讨论(0)
  • 2021-01-02 11:41

    You would need to include your MY_Controller class or auto-load it. I suggest you auto-load it by adding the following to your application/config/config.php file.

    function __autoload($class)
    {
        if (strpos($class, 'CI_') !== 0)
        {
            if (file_exists($file = APPPATH . 'core/' . $class . EXT))
            {
                include $file;
            }
        }
    } 
    
    0 讨论(0)
  • 2021-01-02 11:48

    Make sure the filename is perfectly cased. Linux server is case-sensitive. So if the class name is My_Controller then the name of the file should be My_Controller.php

    0 讨论(0)
  • 2021-01-02 12:01

    in config/config.php

    /* load class in core folder */
    function my_load($class) {        
    
        if (strpos($class, 'CI_') !== 0) {            
            if (is_readable(APPPATH . 'core' . DIRECTORY_SEPARATOR . $class . '.php' )) {                
                require_once (APPPATH . 'core' . DIRECTORY_SEPARATOR . $class . '.php');                
            }
        }
    
    }
    
    spl_autoload_register('my_load');
    
    0 讨论(0)
提交回复
热议问题