Reputation: 11
I have issue in Codeigniter 3.0 with codeof __autoload function in config/config.php It keeps giving the following error
Class 'Frontend_Controller' not found
core/MY_Controller.php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
}
}
libraries/Frontend_Controller.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Frontend_Controller extends MY_Controller {
function __construct() {
parent::__construct();
}
}
libraries/Admin_Controller.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin_Controller extends MY_Controller {
function __construct(){
parent::__construct();
}
}
controllers/Welcome.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends Frontend_Controller {
public function __construct(){
parent::__construct();
}
}
config/config.php
function __autoload($class) {
$path = array('libraries');
if(strpos($class, 'CI_') !== 0) {
foreach($path as $dir) {
$file = APPPATH.$dir.'/'.($class).'.php';
if (file_exists($file) && is_file($file))
@include_once($file);
}
}
}
Upvotes: 1
Views: 676
Reputation: 650
this code work for me for spl_autoload_register()
function autoload($classname)
{
$path = array('libraries');
if(strpos($classname, 'CI_') !== 0)
{
foreach($path as $dir)
{
$file = APPPATH.$dir.'/'.($classname).'.php';
if (file_exists($file) && is_file($file))
@include_once($file);
}
}
}
spl_autoload_register('autoload');
Upvotes: 1
Reputation: 11
It was due to my config.php file setting $config['composer_autoload'] was TRUE which(Composer) prevents MY_ controllers from loading __autoload function. i used spl_autoload_register. e.g.:
function customCIAutoload($classname){
$path = array('libraries');
if(strpos($class, 'CI_') !== 0) {
foreach($path as $dir) {
$file = APPPATH.$dir.'/'.($class).'.php';
if (file_exists($file) && is_file($file))
@include_once($file);
}
}
}
spl_autoload_register('customCIAutoload');
Upvotes: 0