Search code examples
mysqlicodeigniter-2upgradecodeigniter-3php-5.6

CI 2.2.x upgrade to CI 3.0.x core files issues


I just followed the upgrade guide for CI2 to CI3 and don't have encountered any other issues so far. Will probably get some because of the project I converted still uses DataMapper and has some other hooks and third party tools.

So the first problem I encountered so far is that my custom core controllers don't work anymore.

I use for example this depth for my front-end and back-end logic:

  • CI_Controller > MY_Controller > CronController
  • CI_Controller > MY_Controller > FrontendController
  • CI_Controller > MY_Controller > AdminController

CI3 tells me that my controllers/Account.php controller doesn't know the FrontendController class.

Can I tell CI3 to still include my custom classes or is there a new approach for this?


Solution

  • If you used __autoload(){$class} for autoloading your core classes, you should change it with spl_autoload_register(function ($class){}. I.e.:

    spl_autoload_register(function ($class) {
        if (substr($class,0,3) !== 'CI_') {
            if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
                include $file;
            }
        }
    });