我正在为我的应用程序创建一个 S3 插件。在 app/Plugin/S3/Controller/Component/S3Component.php
我有这些:
<?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;
}
}
在我应用的 Controller 中,我使用 $s3 = $this->S3->loadS3();
它抛出错误 Error: Class 'Aws\S3\S3Client' not found
我尝试添加行:App::uses('Vendor', 'aws/Aws/S3/S3Client');
到组件类,并删除 use Aws\S3\S3Client;
。它显示 Error: Class 'S3Client' not found
文件夹 app/Plugin/S3/Vendor/aws
中的 AWS SDK
我正在加载 S3 对象引用:http://docs.aws.amazon.com/aws-sdk-php/guide/latest/quick-start.html#factory-method
解决方案:
在@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
require 'vendor/autoload.php';
因为 CakePHP 不应触及自动加载机制。
关于php - 如何将 AWS SDK 加载到 CakePHP 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22778202/