PHP AWS SDK autoloader conflicts with Codeigniter PHP AWS SDK autoloader conflicts with Codeigniter codeigniter codeigniter

PHP AWS SDK autoloader conflicts with Codeigniter


As you probably know, you don't really want to be modifying the core methods in CI. So, to prevent CI from conflicting with your class, you want to do something very similar to the following:

Leave your folder structure as is, but create a new file outside your aws_sdk folder. Name it something like *Aws_loader* or something that makes sense to you. If you want to autoload the sdk, then in the CI autoloader file, add:

CI Autoload file (application/config/autoload.php):

$autoload['libraries'] = array('Aws_loader');

Your init file:

class CI_Aws_sdk{    // for use with PHP < version 5    /*public function CI_Aws_sdk(){        require dirname(__FILE__) . DIRECTORY_SEPARATOR . "aws_sdk" .DIRECTORY_SEPARATOR . 'sdk.class.php';    }*/    // for use with PHP >= 5    public function __construct(){        require dirname(__FILE__) . DIRECTORY_SEPARATOR . "aws_sdk" .DIRECTORY_SEPARATOR . 'sdk.class.php';    }}

So your directory structure looks like this now:

application --  config --  ...  libraries --    Aws_loader.php    aws_sdk --       sdk.class.php

If you aren't autoloading the sdk, then in your controller, you can do this:

$this->load->library('Aws_loader');

Either way, CI with load the class for you and effectively separate any methods within it and now you can operate within that class just like any other library or model that you've loaded previously, without interfering with CI's methods, similar to this:

$this->Aws_loader->do_something();

You can use the same method for any third party class library or even one that you wrote yourself. A very similar arrangement can be used for models, libraries, helpers and the like.Hope this helps!