Wednesday, August 28, 2013

How to run Composer autoload and CodeIgniter autoload simultaneously

Did you tried to install composer and then you existing CodeIgniter Autoload stop working!!! It happened because __autoload is the old, deprecated way of doing autoloading and you can have only one.

How to run it?
You should register your autoloader using spl_autoload_register.
How you will do it in your code..Here is an example below...

function MY_CI_Autoload($class)
{
 if(strpos($class, 'CI_') !== 0)
 {
  @include_once( APPPATH . 'core/'. $class . EXT );
 }
}

spl_autoload_register('MY_CI_Autoload');

This way your autoloader and composer's will coexist happily.

No comments:

Post a Comment