Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My core class My_head not found in codeigniter

I am trying to create core class in codeigniter. In application/core I create a file with the name of MY_head.php and the code of MY_head.php is:

class MY_head extends CI_Controller{
 
  public function __construct(){
     parent::__construct();
  }
 
  public function load_header(){
      //some code here
  }
}

Now I am trying to extend this class in my controller practice.php the code is:

class Practice extends MY_head{
   public function __construct(){
     parent::__construct();
   }

   function index(){
   }
}

But when I load the practice controller in the browser it says

Fatal error: Class 'MY_head' not found in.

Where is the problem?

Note : $config['subclass_prefix'] = 'MY_';

like image 993
Alicia Dsney Avatar asked Jan 28 '26 04:01

Alicia Dsney


1 Answers

function __autoload($class) is deprecated:

Update for PHP 7.x and up

spl_autoload_register(function($class)
{
    if(strpos($class, 'CI_') !== 0)
    {
        @include_once( APPPATH . 'core/'. $class . '.php' );
    }
});
like image 160
Bart Mommens Avatar answered Jan 29 '26 20:01

Bart Mommens