如何将AWS SDK加载到CakePHP中? [英] How to load AWS SDK into CakePHP?
问题描述
我正在为我的应用程式建立一个S3外挂程式。在 app / Plugin / S3 / Controller / Component / S3Component.php
我有这些:
I'm creating a S3 plugin for my app. In app/Plugin/S3/Controller/Component/S3Component.php
I have these:
<?php
App::import('Vendor', 'aws/aws-autoloader');
use Aws\S3\S3Client;
class S3Component extends Component {
public function loadS3 () {
$s3 = S3Client::factory(array(
'key' => '',
'secret' => ''
));
return $s3;
}
}
在我的应用程序的控制器中,我调用它使用 $ s3 = $ this-> S3-> loadS3();
错误:未找到类'Aws \S3\S3Client'
我尝试添加行: App :: uses('Vendor','aws / Aws / S3 / S3Client');
到组件类,并删除 use Aws \S3\\ \\ S3Client;
。它显示错误:未找到类'S3Client'
I tried adding the line: App::uses('Vendor', 'aws/Aws/S3/S3Client');
to the component class, and removed use Aws\S3\S3Client;
. It shows Error: Class 'S3Client' not found
AWS SDK位于 app / Plugin / S3 / Vendor / aws
The AWS SDK in in the folder app/Plugin/S3/Vendor/aws
我正在加载S3对象,参考:http://docs.aws.amazon.com/aws-sdk-php/guide /latest/quick-start.html#factory-method
I'm loading the S3 object with reference to: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/quick-start.html#factory-method
解决方案:
这是我的组件现在在@akirk的帮助下的样子。
This is how my component looks like now with the help of @akirk.
<?php
ini_set('include_path', ROOT . DS . 'lib' . PATH_SEPARATOR . ini_get('include_path'). PATH_SEPARATOR . ROOT .DS . 'app/Plugin/S3/Vendor/aws');
require ROOT . DS . 'app/Plugin/S3/Vendor/aws/aws-autoloader.php';
use Aws\S3\S3Client;
class S3Component extends Component {
public function loadS3 () {
$s3 = S3Client::factory(array(
'key' => '',
'secret' => ''
));
return $s3;
}
}
推荐答案
显然,自动导入不起作用。你应该像教程中一样,使用 require
Clearly the autoimport doesn't work. You should do it as in the tutorial, use require
require 'vendor/autoload.php';
因为自动加载机制不适用于CakePHP。
as the autoloading mechanism shouldn't be touched by CakePHP.
这篇关于如何将AWS SDK加载到CakePHP中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!