如何加载AWS SDK到CakePHP的? [英] How to load AWS SDK into CakePHP?
问题描述
我创建一个S3插件我的应用程序。在应用程序/插件/ S3 /控制器/组件/ S3Component.php
我有这些:
< PHP
应用::进口(供应商,AWS / AWS-自动加载机);
使用AWS \ S3 \ S3Client;
类S3Component扩展组件{
公共职能loadS3(){
$ S3 = S3Client ::工厂(阵列(
'键'=> '',
秘密=> ''
));
返回$ S3;
}
}
在我的应用程序的控制,我把它用 $ S3 = $这个 - > S3-> loadS3();
这引发错误错误:类'AWS \ S3 \ S3Client'未找到
我尝试添加该行:应用::使用(供应商,AWS / AWS / S3 / S3Client');
的组件类,并删除使用AWS \ S3 \ S3Client;
。它显示了错误:类'S3Client'未找到
在AWS SDK中的文件夹应用程序/插件/ S3 /供应商/ AWS
我加载了S3对象参考:的http://docs.aws.amazon.com/aws-sdk-php/guide/latest/quick-start.html#factory-method
解决方法:
这是我的组件现在看起来像@akirk的帮助。
< PHP
ini_set('include_path中,ROOT DS'库'PATH_SEPARATOR ini_get('include_path中)PATH_SEPARATOR ROOT .DS应用程序/插件/ S3 /供应商/ AWS。。。。。);
需要ROOT。 DS。 应用程序/插件/ S3 /供应商/ AWS / AWS-autoloader.php;
使用AWS \ S3 \ S3Client;
类S3Component扩展组件{
公共职能loadS3(){
$ S3 = S3Client ::工厂(阵列(
'键'=> '',
秘密=> ''
));
返回$ S3;
}
}
显然,AUTOIMPORT不起作用。你应该这样做在本教程中,使用要求
要求供应商/ autoload.php;
作为自动加载机制不应被CakePHP的感动。
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;
}
}
In my app's controller, I call it using $s3 = $this->S3->loadS3();
It throws the error Error: Class 'Aws\S3\S3Client' not found
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
The AWS SDK in in the folder app/Plugin/S3/Vendor/aws
I'm loading the S3 object with reference to: http://docs.aws.amazon.com/aws-sdk-php/guide/latest/quick-start.html#factory-method
Solution:
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;
}
}
Clearly the autoimport doesn't work. You should do it as in the tutorial, use require
require 'vendor/autoload.php';
as the autoloading mechanism shouldn't be touched by CakePHP.
这篇关于如何加载AWS SDK到CakePHP的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!