In Codeigniter 2.1.2 I want to create base controller and then extends from this controller. It does not work and I have no idea why and I'm pretty desperate now.
In \application\core\MY_Base_Controller.php I have this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Base_Controller extends CI_Controller
{
function __construct()
{
parent::__construct();
...
In \application\controllers\Home.php I have this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MY_Base_Controller {
And the error message is
Fatal error: Class 'MY_Base_Controller' not found in ...\application\controllers\Home.php on line 3
I have no idea what to do, I read all over the internet that I have to put base controller to core folder what I did, that I have to name base controller with prefix MY_, I did. But it is still no working. And in my config.php is this line as well
$config['subclass_prefix'] = 'MY_';
Im running this on localhost using xampp
Thank you for your help
EDIT
Could someone please downlod following link try it, and tell me whats wrong. I have just downloaded codeigniter tried to create base controller and extend welcome controller. Not working. In following rar there are just modified files. Thank you http://goo.gl/sKHkDl
EDIT 2
I'm able to get this working by renaming MY_Base_Controller to MY_Controller. Does this mean, I'm able to create only one extended class for a controller ? eg. I can not have
Just and only MY_Controller ?
I've had the same issue in my first CI application and found two key elements that need to be checked:
1. Case Matching: Depending on your server configuration, the name of your file in the directory will need to match the case of your class. For instance, where your class is called "MY_Controller" your file name will need to be: "MY_Controller.php" on a Linux server. Windows servers have been known to have issues with uppercase filenames so you might experiment naming your controller "my_controller.php" and/or changing the extension to "my_" in your config.php instead of "MY_"
2. Insert an Autoloading function For reasons unknown to me, Codeigniter does not automatically recognize and read extended core classes before first loading the core class. This can cause issues with your extension not loading in correctly. To remedy this, you can add this simple autoloading script to the very bottom of your config.php
/*
|--------------------------------------------------------------------------
| Autoload Custom Controllers
|--------------------------------------------------------------------------
|
*/
function __autoload($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
}
Side note: the solution above was tested on CodeIgniter 2.1.4. The question asked involved CodeIgniter 2.1.2