Вопрос

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.


Edit March 20th 2014:

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;
        }
    }
}  

  1. Create /application/core/Backend/Backend_Controller.php like this:

(defined('BASEPATH')) OR exit('No direct script access allowed');

class Backend_Controller extends CORE_Controller {

}
  1. I have a Menu class extends Backend_Controller. Then receive this error 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;
        }
    }
}  
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top