How to install the AWS SDK in Yii

2019-04-11 06:41发布

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??

4条回答
做自己的国王
2楼-- · 2019-04-11 07:24

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);
查看更多
▲ chillily
3楼-- · 2019-04-11 07:24

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();
查看更多
男人必须洒脱
4楼-- · 2019-04-11 07:28

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

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

查看更多
放荡不羁爱自由
5楼-- · 2019-04-11 07:41

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.

查看更多
登录 后发表回答