- I'm using Codeigniter 2.1.0.
- I'm including the Amazon Web Services SDK in a custom model using
require_once APPPATH . "/libraries/aws_sdk/sdk.class.php";
This works well. However when CI decides it later needs to load it's db cache class, it calls (via CI_DB_driver::_cache_init):
if ( ! class_exists('CI_DB_Cache'))
{
if ( ! @include(BASEPATH.'database/DB_cache.php'))
{
return $this->cache_off();
}
}
This triggers the autoload of the AWS SDK (the exact method being CFLoader::autoloader
).
I can get around this by telling class_exists
not to autoload, as it seems that DB_cache.php is included anyway if class_exists
returns false:
if ( ! class_exists('CI_DB_Cache', false))
{
if ( ! @include(BASEPATH.'database/DB_cache.php'))
{
return $this->cache_off();
}
}
This dirty fix works, but obviously only fixes the immediate problem. In general, what is the best way to ensure that CodeIgniter doesn't get confused with the autoload from other libraries?
Please note:
- I've read bits and pieces about using
spl_autoload_register
. It seems that Codeigniter doesn't use this and I'm not sure how I should implement this safely. I would find a solid example of how and where I should implement this most useful (if, of course, this is the solution). - It appears that the AWS SDK already uses
spl_autoload_register
:spl_autoload_register(array('CFLoader', 'autoloader'));