简体   繁体   中英

How to install the AWS SDK in Yii

I would like to use the Amazon AWS SDK for PHP in my Yii project, however I get all kinds of include errors (such as include(CFCredentials.php): failed to open stream: No such file or directory ).

I think it may be related to Yii's assumption that class names must match file names...

What can we do??

I've made that:

spl_autoload_unregister(array('YiiBase', 'autoload'));
require_once PATH_TO_AWS_SDK . 'sdk.class.php';
// I write down in PATH_TO_AWS_SDK.'config.inc.php' my CFCredentials
spl_autoload_register(array('YiiBase', 'autoload'));

$amazon_opts = array(
    'curlopts' => array(
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_FORBID_REUSE   => false,
    ),
);
$amazon = new AmazonSES();
$response = $amazon->get_send_quota($amazon_opts);

This worked beautifully:

// Include the SDK

Yii::import('application.vendors.aws.*');
spl_autoload_unregister(array('YiiBase', 'autoload'));
require_once 'sdk.class.php';
spl_autoload_register(array('YiiBase', 'autoload'));

// Instantiate the AmazonEC2 class
$ec2 = new AmazonEC2();

In case someone stumbles upon this issue, I've found that if one is using the PHAR file directly (poor decision, I know) and importing via require_once, you cannot call spl_autoload_register to re-add YiiBase autoload until after your SDK call is complete.

At least this was our case when using the StsClient to call assume role with an IAM role.

This is more easier way, You can use Yii S3 Upload extension.

http://www.yiiframework.com/extension/s3upload/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM