In my application/core
directory, I had class MY_Controller
. And now, I want to create two classes in two paths application/core/Frontent/Frontend_Controller.php
and application/core/Backend/Backend_Controller.php
. Then my modules controllers extend from Frontend_Controller and Backend_Controller class. But CI always raises class not found error.
I used @manix's suggestion: 1. Write below script at the end of /application/config/config.php
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/Frontend/' . $class . EXT))
{
include $file;
}
if (file_exists($file = APPPATH . 'core/Backend/' . $class . EXT))
{
include $file;
}
}
}
/application/core/Backend/Backend_Controller.php
like this:
(defined('BASEPATH')) OR exit('No direct script access allowed');
class Backend_Controller extends CORE_Controller {
}
Fatal error: Class 'Backend_Controller' not found in codeigniter\application\widgets\menu\Controllers\menu.php on line 6
. If I put the Backend_Controller.php at /application/core/Backend_Controller.php
, it is OK. But I want to put it into a subfolder.SOLUTION (update March 24th 2014) Thank to manix. I edited from his code to load classes. Here is the code that works for me.
function __autoload($class) {
if (strpos($class, 'CI_') !== 0) {
if (file_exists($file = APPPATH . 'core/Frontent/' . $class . EXT)) {
include $file;
}
if (file_exists($file = APPPATH . 'core/Backend/' . $class . EXT)) {
include $file;
}
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
}
Try to call explicitly the __autoload
funtionat the end of the config.php file that raised at application/config/
folder. Look the example above:
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/Frontent/' . $class . EXT))
{
include $file;
}
if (file_exists($file = APPPATH . 'core/Backend/' . $class . EXT))
{
include $file;
}
}
}