I created a core controller named Role_Admin and set the config prefix
$config['subclass_prefix'] = 'Role_';
Here is the code for the Role_Admin.php in the core folder
class Role_Admin extends CI_Controller {
function __construct() {
}
}
In the controller folder when I write
class admin extends Role_Admin { ... }
I get
Fatal error: Class ‘Role_Admin’ not found
Is something wrong in what I am doing.
edit: (i created a quick fix that is much better, any new core file that you create just extend the MY_Controller. Then in your controller directory you can extend any Core controller that you created
class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
//include custom core classes
$core_path = DOCUMENT_ROOT . '/application/core';
$this->load->helper('file');
foreach(get_filenames($core_path) as $file) {
if ($file != 'MY_Controller.php') {
if(file_exists($file)) {
include_once($file);
}
}
}
}
}
The setting you have for
$config['subclass_prefix']is fine, but your file name is incorrect. CI is looking for the fileRole_Controller.php, notRole_Admin.php.There’s an easier way to do this, and although it might appear to be a hack it is totally legit. Go back to the
MY_prefix, createMY_Controller.php, and in that file, just define the controller classes you want to use. You actually don’t even need aMY_Controllerclass. Example:All these classes will be available for your controllers to extend.